-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
支持了生词本:通过bash函数为kd增加了自动将查询历史记录保存到生词本的功能 #37
Comments
感谢反馈,我加到README里面了 https://github.com/Karmenzind/kd?tab=readme-ov-file#%E7%94%9F%E8%AF%8D%E6%9C%AC 其实可以直接改成调用两次kd,第二次加上NO_COLOR,因为直接走缓存所以开销为零。这样也方便对结果做处理,比如: ff() {
kd $1
txt=$(NO_COLOR=1 kd $1)
if [[ "$txt" == Not\ found* ]]; then
return
fi
echo "$txt" >> $vocabfile
echo "============================================" >> $vocabfile
} |
感谢提示,我直接把这个统计查词频率的json文件改成了软链接,这样可以同步更新到github仓库 |
另外经过一段时间的实际使用,建议 alias f='kd'
alias ff='kd -t'\ 按两次f才能翻译一个单词还是太麻烦了,"f 单词"翻译单词,"ff 句子"翻译句子,尽可能保证阅读时的连贯性,不把时间浪费在打字上 |
最终版本 ExaithrgVocabBookDir=~/github/exaithrg/vocab_book
git_pull_vocab_book_func() {
local current_dir=$(pwd)
cd "$ExaithrgVocabBookDir" || {
echo "Error: Failed to change directory to $ExaithrgVocabBookDir"
return 1
}
git pull
cd "$current_dir"
# echo "Auto update completed successfully"
}
git_push_vocab_book_func() {
local current_dir=$(pwd)
cd "$ExaithrgVocabBookDir" || {
echo "Error: Failed to change directory to $ExaithrgVocabBookDir"
return 1
}
git add . || {
echo "Error: Failed to add changes"
return 1
}
git commit -m "auto update"
git push
cd "$current_dir"
echo "Auto update completed successfully"
}
# Version A
# "sudo apt install expect" to support command "unbuffer"
# kd_func() {
# mkdir -p "$ExaithrgVocabBookDir"
# echo "========================================================================" >> "$ExaithrgVocabBookDir/vocab_book.txt"
# unbuffer kd "$@" | tee -ai >(sed 's/\x1b\[[0-9;]*m//g' >> "$ExaithrgVocabBookDir/vocab_book.txt")
# echo "" >> "$ExaithrgVocabBookDir/vocab_book.txt"
# }
# kdl_func() {
# mkdir -p "$ExaithrgVocabBookDir"
# echo "========================================================================" >> "$ExaithrgVocabBookDir/vocab_book.txt"
# unbuffer kd -t "$@" | tee -ai >(sed 's/\x1b\[[0-9;]*m//g' >> "$ExaithrgVocabBookDir/vocab_book.txt")
# echo "" >> "$ExaithrgVocabBookDir/vocab_book.txt"
# }
# Version B
kd_func() {
local txt
kd "$@"
mkdir -p "$ExaithrgVocabBookDir"
txt=$(NO_COLOR=1 kd "$@")
# if [[ "$txt" == Not\ found* ]]; then
# return
# fi
echo "========================================================================" >> "$ExaithrgVocabBookDir/vocab_book.txt"
echo ">>> $@" >> "$ExaithrgVocabBookDir/vocab_book.txt"
echo "$txt" >> "$ExaithrgVocabBookDir/vocab_book.txt"
echo "" >> "$ExaithrgVocabBookDir/vocab_book.txt"
}
kdl_func() {
local txt
kd -t "$@"
mkdir -p "$ExaithrgVocabBookDir"
txt=$(NO_COLOR=1 kd -t "$@")
# if [[ "$txt" == Not\ found* ]]; then
# return
# fi
echo "========================================================================" >> "$ExaithrgVocabBookDir/vocab_book.txt"
echo ">>> $@" >> "$ExaithrgVocabBookDir/vocab_book.txt"
echo "$txt" >> "$ExaithrgVocabBookDir/vocab_book.txt"
echo "" >> "$ExaithrgVocabBookDir/vocab_book.txt"
}
alias kdl='kd -t'
alias f='kd_func'
alias 发='kd_func'
alias F='kd_func'
alias ff='kdl_func'
alias FF='kdl_func'
alias fff='kdl_func'
alias FFF='kdl_func'
alias ffpush='git_push_vocab_book_func'
alias ffpull='git_pull_vocab_book_func'
alias ffp='git_push_vocab_book_func'
alias ggp='git_push_vocab_book_func'
alias ffl='git_pull_vocab_book_func' |
🤣 这么多alias |
实际上用到现在只有这几个用的比较多,其他的忘删了 alias f='kd_func'
alias 发='kd_func'
alias ff='kdl_func'
alias ffp='git_push_vocab_book_func'
alias ffl='git_pull_vocab_book_func' |
通过bash函数添加了生词本。可以将下述代码加入到.bashrc或.zshrc中,从而让kd命令能够自动将所有查询历史记录都追加保存到一个词汇表(vocabulary book)中。同时,增加了直接同步和github上的远程单词表的函数。
The text was updated successfully, but these errors were encountered: