6个版本
0.2.4 | 2021年2月2日 |
---|---|
0.2.3 | 2021年2月2日 |
0.2.1 | 2020年9月22日 |
0.0.2 | 2020年9月22日 |
0.0.1 | 2020年6月1日 |
#1198 in 文本处理
7KB
113 行
一个简单的单词计数器
输入单词并计算出现次数。
我的第一个Rust项目。
安装
cargo install wcounter
用法
将单词添加到wcounter,并按出现顺序显示单词列表。
> wcounter --dest-file="path/to/file" add some_word
> wcounter --dest-file="path/to/file" add some_word2
> wcounter --dest-file="path/to/file" add some_word3
> wcounter --dest-file="path/to/file" add some_word2
# shows by ascending
> wcounter --dest-file="path/to/file" show
some_word
some_word3
some_word2
# shows by descending
> wcounter --dest-file="path/to/file" show --reverse
some_word2
some_word3
some_word
...
与Zsh和FZF集成
受这篇文章的启发
typeset -U chpwd_functions
## save the current directory after cd
CD_HISTORY_FILE=${HOME}/.cd_history_file # cd history filcd history file
function chpwd_record_history() {
echo $PWD | xargs wcounter --dest-file=${CD_HISTORY_FILE} add
}
chpwd_functions=($chpwd_functions chpwd_record_history)
## load the cd history
function fd(){
dest=$(wcounter --dest-file=${CD_HISTORY_FILE} show --reverse | fzf +m --query "$LBUFFER" --prompt="cd > ")
cd $dest
}
文件锁定
为了避免多个进程同时写入输出文件时的冲突,wcounter使用cluFlock。锁定文件将创建在 {dest_file_path}.lock
,并且将被其他进程重用,因此锁定文件不会自动删除。
依赖项
~2.1–3.5MB
~60K SLoC