溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

fzf設計是怎樣的

發布時間:2021-10-19 15:58:27 來源:億速云 閱讀:182 作者:柒染 欄目:大數據

fzf設計是怎樣的,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

fzf說明

fzf本身是一個非??焖俚?、通用的,模糊匹配/嚴格匹配或是否區分大小寫的命令行匹配工具,不僅僅可以支持文件、歷史命令,可以支持其他任何通用的內容的匹配。

問題

fzf用于匹配文件時,每次啟動都會重新掃描磁盤上的文件列表(而且貌似是深度優先),導致一個問題: 如果文件數量較大,經常搜索不到很淺的目錄中的文件。

fzf目前還是主要被vim等編輯器用在項目級別的文件匹配,還無法像everything一樣全局/系統級的文件匹配。 如果想做到后者的目的,感覺可以從以下幾點進行優化:

  1. 在后臺運行一個daemon進程,緩存文件列表

  2. 把文件列表緩存在文件中,避免下次大范圍掃描磁盤

  3. 通過inotify等機制監視文件的實時變

2019-12-12 補充

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設計是怎樣的的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

fzf
AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女