aperezdc / zsh-fzy

Use the fzy fuzzy-finder in Zsh
MIT License
55 stars 9 forks source link
fuzzy-finder fzy plugin zsh

zsh-fzy

zsh-fzy is a zsh plugin that uses fzy for certain fuzzy matching operations. The plugin defines the following Zle widgets:

Installation

It can be installed manually, or by using a plugin manager, e.g. zplug:

zplug aperezdc/zsh-fzy

Configuration

By default the widgets defined by the plugin are not bound. A typical configuration could be:

# ALT-C: cd into the selected directory
# CTRL-T: Place the selected file path in the command line
# CTRL-R: Place the selected command from history in the command line
# CTRL-P: Place the selected process ID in the command line
bindkey '\ec' fzy-cd-widget
bindkey '^T'  fzy-file-widget
bindkey '^R'  fzy-history-widget
bindkey '^P'  fzy-proc-widget

Additional configuration is done using Zsh styles. The following lists the available styles and their defaults:

zstyle :fzy:tmux    enabled      no

zstyle :fzy:history show-scores  no
zstyle :fzy:history lines        ''
zstyle :fzy:history prompt       'history >> '
zstyle :fzy:history command      fzy-history-default-command

zstyle :fzy:file    show-scores  no
zstyle :fzy:file    lines        ''
zstyle :fzy:file    prompt       'file >> '
zstyle :fzy:file    command      fzy-file-default-command

zstyle :fzy:cd      show-scores  no
zstyle :fzy:cd      lines        ''
zstyle :fzy:cd      prompt       'cd >> '
zstyle :fzy:cd      command      fzy-cd-default-command

zstyle :fzy:proc    show-scores  no
zstyle :fzy:proc    lines        ''
zstyle :fzy:proc    prompt       'proc >> '
zstyle :fzy:proc    command      fzy-proc-default-command

Setting :fzy:tmux enabled will use a split pane when the shell is running inside Tmux. Currently there are no options to allow configuration of the Tmux pane used for the widgets. Contributions to address this are very welcome, as well as day-to-day testing with this option enabled.

For each widget, the :fzy:${widget} context contains the following options:

Commands

Commands used to generate lists of candidate entries for completoin must write items to standard output, one per line. Commands fzy-file-default-command, fzy-cd-default-command, and fzy-history-default-command are used by default. The first two use find(1) under the hood, and you may prefer to use other tools like RipGrep to produce the list of candidate elements shown by the widgets:

zstyle :fzy:file command rg --files

Note that the command settings are arrays, please take it into account when specifying them:

zstyle :fzy:file command rg --files    # Correct. Array of two elements.
zstyle :fzy:file command 'rg --files'  # Incorrect. Array of one element.