Skip to content
Steven edited this page Jan 23, 2021 · 23 revisions

You can make full use of fzf's --preview option when using fzf-tab . If you don't know what it is, please read junegunn/fzf#preview-window first.

An example:

zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath' # remember to use single quote here!!!

图片

Variables

fzf-tab defines some variables for better previewing.

$desc

This is the string fzf shows to you.

Example: --accessed use the accessed timestamp field, README.md

$word

This is the real string to be insert into your commandline.

For example, if the $desc is --accessed use the accessed timestamp field, the $word is --accessed.

$group

This is the description of the group which the $word belongs to.

For example, --accessed belongs to group named [option], and README.md belongs to [filename].

README.md belongs to [filename] to completing exa, but belongs to [files] when completing ls.

NOTE: To use this variable, please make sure you have set zstyle ':completion:*:descriptions' format '[%d]'.

$realpath

If you are completing a path and want to access this path when previewing, then you should use $realpath.

For example, if you are completing directories in /usr/, $word will be something like bin, lib, but $realpath will be /usr/bin, /usr/lib.

Preview gallery

Feel free to contribute your preview~

[kill/ps] preview of full commandline arguments

图片

# give a preview of commandline arguments when completing `kill`
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-preview \
  [[ $group == "[process ID]" ]] && ps --pid=$word -o cmd --no-headers -w -w'
zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-flags --preview-window=down:3:wrap

note there is a "'" symbol above to the left of the "[[ $group... " that for some reason doesn't render when copying and pasting the above text

Clone this wiki locally