es+fzf:超快速找檔神器-用Everything Search的命令行es.exe,整合fzf的模糊搜尋;WSL也能使用!

本文介紹兩個命令行工具:

  1. es.exe:Evcerything Search圖形介面工具的命令行
  2. fzf(Fast fuZzy Finder):模糊搜尋檔名工具,有Windows與*nix版本

用es.exe快速查出符合檔名後再交給fzf繼續縮小範圍並上下選取要操作的檔案。

更棒的是:在WSL 2裡可以直接用es.exe,找檔案的速度比fzf、locate或find等更是快上許多,再結合fzf就能快速切換目錄與執行檔案。

Everything Search與es.exe

自從2008年開始使用Everything Search後(參考:用Everything在電光石火間找到迷失的檔案),Everything變成必備工具,它直接由NTFS索引搜尋檔名,速度超快,極大地增進了工作效率。

而es.exe則是Everything的命令行客戶端工具,亦即Everything扮演伺服器角色,es.exe透過內部處理通訊(IPC,Inter-Process Commnuication)發出查詢字串給Everything並取回回應,再顯示在命令提示字元裡。es.exe做為客戶端,執行時Everything必須運行才能正確執行,若Everything未啟動,則會顯示下列錯誤訊息:

Error 8: Everything IPC window not found. Please make sure Everything is running.

es.exe下載:ES 1.1 Command Line Tool for Everything 1.4.1,下載最新的1.1.0.18版。

es.exe命令行選項

es.exe的執行選項很多,用 -h 會查詢說明;選項有 5 大類:

  1. 搜尋選項
  2. 排序選項
  3. 顯示選項
  4. 匯出選項
  5. 一般選項

以下是我常用的幾個:

  • 用正則運算式:es -r dropbox$
  • 顯示日期與檔案大小:es -dm -size .pdf
    • -dm:Date Modified
    • -dc:Date Created
    • -da:Date Accessed
  • 顯示日期、檔案大小與高亮顯示:es -dm -size -highlight .pdf
  • 加上-no或-no-就是取消,如-nosize
  • 用-save-settings將常用選項寫入登錄使能重複套用。-clear-settings則是清除設定
es.exe -dm -size -sizecolor 0x0d -dmcolor 0x0b -highlight -highlight-color 0x0e -save-settings

▼ 顏色代表碼(0x00~0xff)
es-colors

  • 下列選項和 dir 相同,可組合使用:
    • 選項開頭字元可斜線 / 或減號 - 皆可使用
    • /ad:只列出目錄(Attribute Directory)
    • /a-d:只列出檔案
    • /od:用日期由小到大排序(Order by Date Ascending)
    • /o-d:用日期由大到小排序(Order by Date Descending)
    • 以上把d換成s就是檔案大小(Size),n是檔名,e是面副檔名
  • es.exe搜尋按Ctrl+C中斷後,若出現字體顏色被改變,可以用color還原

與fzf整合

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
cd ~/.fzf/
./install
source ~/.zshrc

fzf輸入格式

  • 按〔Esc〕或輸入exit關閉視窗
  • 按〔Enter〕選用並關閉視窗,傳出的文字最後帶有換行符號
輸入字串 符合類型 說明
sbtrkt fuzzy-match Items that match sbtrkt
'wild exact-match (quoted) Items that include wild
^music prefix-exact-match Items that start with music
.mp3$ suffix-exact-match Items that end with .mp3
!fire inverse-exact-match Items that do not include fire
!^music inverse-prefix-exact-match Items that do not start with music
!.mp3$ inverse-suffix-exact-match Items that do not end with .mp3

Windows裡如何使用es與fzf

  • 不像*nix能做多種變化,Windows裡我找到的方法:只能用剪貼簿。因為只要取回目錄名或檔名,因此不顯示日期與檔案大小:
es.exe -nodm -nosize -r dropbox$ | fzf | clip
cd 貼入剪貼簿內容
  • 必須切換為Unicode字碼頁,fzf才能正確顯示中文字:chcp 65001

es.exe選項

es -h:

ES 1.1.0.18
ES is a command line interface to search Everything from a command prompt.
ES uses the Everything search syntax.

Usage: es.exe [options] search text
Example: ES  Everything ext:exe;ini 


Search options
   -r <search>, -regex <search>
        Search using regular expressions.
   -i, -case
        Match case.
   -w, -ww, -whole-word, -whole-words
        Match whole words.
   -p, -match-path
        Match full path and file name.
   -a, -diacritics
        Match diacritical marks.

   -o <offset>, -offset <offset>
        Show results starting from offset.
   -n <num>, -max-results <num>
        Limit the number of results shown to <num>.

   -path <path>
        Search for subfolders and files in path.
   -parent-path <path>
        Search for subfolders and files in the parent of path.
   -parent <path>
        Search for files with the specified parent path.

   /ad
        Folders only.
   /a-d
        Files only.
   /a[RHSDAVNTPLCOIE]
        DIR style attributes search.
        R = Read only.
        H = Hidden.
        S = System.
        D = Directory.
        A = Archive.
        V = Device.
        N = Normal.
        T = Temporary.
        P = Sparse file.
        L = Reparse point.
        C = Compressed.
        O = Offline.
        I = Not content indexed.
        E = Encrypted.
        - = Prefix a flag with - to exclude.


Sort options
   -s
        sort by full path.
   -sort <name[-ascending|-descending]>, -sort-<name>[-ascending|-descending]
        Set sort
        name=name|path|size|extension|date-created|date-modified|date-accessed|
        attributes|file-list-file-name|run-count|date-recently-changed|date-run
   -sort-ascending, -sort-descending
        Set sort order

   /on, /o-n, /os, /o-s, /oe, /o-e, /od, /o-d
        DIR style sorts.
        N = Name.
        S = Size.
        E = Extension.
        D = Date modified.
        - = Sort in descending order.


Display options
   -name
   -path-column
   -full-path-and-name, -filename-column
   -extension, -ext
   -size
   -date-created, -dc
   -date-modified, -dm
   -date-accessed, -da
   -attributes, -attribs, -attrib
   -file-list-file-name
   -run-count
   -date-run
   -date-recently-changed, -rc
        Show the specified column.

   -highlight
        Highlight results.
   -highlight-color <color>
        Highlight color 0-255.

   -csv
   -efu
   -txt
   -m3u
   -m3u8
        Change display format.

   -size-format <format>
        0=auto, 1=Bytes, 2=KB, 3=MB.
   -date-format <format>
        0=auto, 1=ISO-8601, 2=FILETIME, 3=ISO-8601(UTC)

   -filename-color <color>
   -name-color <color>
   -path-color <color>
   -extension-color <color>
   -size-color <color>
   -date-created-color <color>, -dc-color <color>
   -date-modified-color <color>, -dm-color <color>
   -date-accessed-color <color>, -da-color <color>
   -attributes-color <color>
   -file-list-filename-color <color>
   -run-count-color <color>
   -date-run-color <color>
   -date-recently-changed-color <color>, -rc-color <color>
        Set the column color 0-255.

   -filename-width <width>
   -name-width <width>
   -path-width <width>
   -extension-width <width>
   -size-width <width>
   -date-created-width <width>, -dc-width <width>
   -date-modified-width <width>, -dm-width <width>
   -date-accessed-width <width>, -da-width <width>
   -attributes-width <width>
   -file-list-filename-width <width>
   -run-count-width <width>
   -date-run-width <width>
   -date-recently-changed-width <width>, -rc-width <width>
        Set the column width 0-200.

   -no-digit-grouping
        Don't group numbers with commas.
   -size-leading-zero
   -run-count-leading-zero
        Format the number with leading zeros, use with -no-digit-grouping.
   -double-quote
        Wrap paths and filenames with double quotes.


Export options
   -export-csv <out.csv>
   -export-efu <out.efu>
   -export-txt <out.txt>
   -export-m3u <out.m3u>
   -export-m3u8 <out.m3u8>
        Export to a file using the specified layout.
   -no-header
        Do not output a column header for CSV and EFU files.


General options
   -h, -help
        Display this help.

   -instance <name>
        Connect to the unique Everything instance name.
   -ipc1, -ipc2
        Use IPC version 1 or 2.
   -pause, -more
        Pause after each page of output.
   -hide-empty-search-results
        Don't show any results when there is no search.
   -empty-search-help
        Show help when no search is specified.
   -timeout <milliseconds>
        Timeout after the specified number of milliseconds to wait for
        the Everything database to load before sending a query.

   -set-run-count <filename> <count>
        Set the run count for the specified filename.
   -inc-run-count <filename>
        Increment the run count for the specified filename by one.
   -get-run-count <filename>
        Display the run count for the specified filename.
   -get-result-count
        Display the result count for the specified search.
   -get-total-size
        Display the total result size for the specified search.
   -save-settings, -clear-settings
        Save or clear settings.
   -version
        Display ES major.minor.revision.build version and exit.
   -get-everything-version
        Display Everything major.minor.revision.build version and exit.
   -no-result-error
        Set the error level if no results are found.


Notes 
    Internal -'s in options can be omitted, eg: -nodigitgrouping
    Switches can also start with a /
    Use double quotes to escape spaces and switches.
    Switches can be disabled by prefixing them with no-, eg: -no-size.
    Use ^ to escape \, &, |, >, < and ^.

WSL 2的應用

下回分解。

相關連結

解說影片

##

您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *