fzf設計是怎樣的,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
fzf本身是一個非??焖俚?、通用的,模糊匹配/嚴格匹配或是否區分大小寫的命令行匹配工具,不僅僅可以支持文件、歷史命令,可以支持其他任何通用的內容的匹配。
fzf用于匹配文件時,每次啟動都會重新掃描磁盤上的文件列表(而且貌似是深度優先),導致一個問題: 如果文件數量較大,經常搜索不到很淺的目錄中的文件。
fzf目前還是主要被vim等編輯器用在項目級別的文件匹配,還無法像everything一樣全局/系統級的文件匹配。 如果想做到后者的目的,感覺可以從以下幾點進行優化:
在后臺運行一個daemon進程,緩存文件列表
把文件列表緩存在文件中,避免下次大范圍掃描磁盤
通過inotify等機制監視文件的實時變
fzf官方提供了很多好用的方法,可以自己看情況使用: https://github.com/junegunn/fzf/wiki/examples
例如:
# fd - cd to selected directory
fda() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# Another fd - cd into the selected directory
# This one differs from the above, by only showing the sub directories and not
# showing the directories within those.
fd() {
DIR=`find * -maxdepth 0 -type d -print 2> /dev/null | fzf-tmux` \
&& cd "$DIR"
}
# fe [FUZZY PATTERN] - Open the selected file with the default editor
# - Bypass fuzzy finder if there's only one match (--select-1)
# - Exit if there's no match (--exit-0)
fe() {
local files
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
}
# fkill - kill processes - list only the ones you can kill. Modified the earlier script.
fkill() {
local pid
if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}看完上述內容,你們掌握fzf設計是怎樣的的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。