/fz

Cli shell plugin, the missing fuzzy tab completion feature of z

Primary LanguageShellMIT LicenseMIT

fz

A shell plugin that seamlessly adds fuzzy search to tab completion of z, lets you easy to jump around among your historical directories. Not any additional key binding is needed. Currently supports Bash and zsh.

Demo

Watch video demo here.

gif-demo

Installation

By simply sourcing corresponding script file for your shell, you're all set. However, this plugin is sitting on top of z and fzf, so you must have them installed as well.

macOS

Bash

  1. Install fzf via Homebrew.

    brew install findutils fzf
  2. Download z and fz.

    mkdir ~/.bash_completion.d
    curl "https://raw.githubusercontent.com/rupa/z/master/{z.sh}" \
        -o ~/.bash_completion.d/"#1"
    curl "https://raw.githubusercontent.com/changyuheng/fz/master/{fz.bash}" \
        -o ~/.bash_completion.d/"#1"
  3. Add the following content to ~/.bashrc:

    if [ -d ~/.bash_completion.d ]; then
      for file in ~/.bash_completion.d/*; do
        . $file
      done
    fi

zsh

  1. Install fzf via Homebrew.

    brew install findutils fzf
  2. Install z and fz via zplug. Add the following content to ~/.zshrc:

    zplug "rupa/z", use:z.sh
    zplug "changyuheng/fz"

Ubuntu

Bash

  1. Install fzf.

    git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
    ~/.fzf/install
  2. Download z and fz.

    mkdir ~/.bash_completion.d
    curl "https://raw.githubusercontent.com/rupa/z/master/{z.sh}" \
        -o ~/.bash_completion.d/"#1"
    curl "https://raw.githubusercontent.com/changyuheng/fz/master/{fz.bash}" \
        -o ~/.bash_completion.d/"#1"
  3. Add the following content to ~/.bashrc:

    if [ -d ~/.bash_completion.d ]; then
      for file in ~/.bash_completion.d/*; do
        . $file
      done
    fi

zsh

  1. Install fzf.

    git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
    ~/.fzf/install
  2. Install z and fz via zplug. Add the following content to ~/.zshrc:

    zplug "rupa/z", use:z.sh
    zplug "changyuheng/fz"

Usage

  • tab/shift-tab, ctrl-n/ctrl-p, ctrl-j/ctrl-k, for next and previous item. Enter for selection. Check fzf’s doc for the search syntaxes.
  • The function of fz is pretty much like what it is of z. -c restricts the search base starting from current working directory. Check z’s doc for more information.
  • Set environment variable FZ_SUB_DIR_TRAVERSAL_ENABLED=1 to enable subdirectory completion. (Currently only supports zsh.)

See Also

License

This software is licensed under a MIT License.