Home

Awesome

fzf-git.sh

bash and zsh key bindings for Git objects, powered by fzf.

<img width="1680" alt="image" src="https://user-images.githubusercontent.com/700826/185568470-20d70937-eea4-4274-aec5-14dfe7ee2de6.png">

Each binding will allow you to browse through Git objects of a certain type, and select the objects you want to paste to your command-line.

Installation

  1. Install the latest version of fzf
    • (Optional) Install bat for syntax-highlighted file previews
  2. Source fzf-git.sh file from your .bashrc or .zshrc

Usage

List of bindings

[!WARNING] You may have issues with these bindings in the following cases:

To workaround the problems, you can use <kbd>CTRL-G</kbd><kbd>{key}</kbd> instead of <kbd>CTRL-G</kbd><kbd>CTRL-{KEY}</kbd>.

[!WARNING] If zsh's KEYTIMEOUT is too small (e.g. 1), you may not be able to hit two keys in time.

Inside fzf

Customization

# Redefine this function to change the options
_fzf_git_fzf() {
  fzf --height=50% --tmux 90%,70% \
    --layout=reverse --multi --min-height=20 --border \
    --border-label-pos=2 \
    --color='header:italic:underline,label:blue' \
    --preview-window='right,50%,border-left' \
    --bind='ctrl-/:change-preview-window(down,50%,border-top|hidden|)' "$@"
}

Defining shortcut commands

Each binding is backed by _fzf_git_* function so you can do something like this in your shell configuration file.

gco() {
  _fzf_git_each_ref --no-multi | xargs git checkout
}

gswt() {
  cd "$(_fzf_git_worktrees --no-multi)"
}

Environment Variables

VariableDescriptionDefault
BAT_STYLESpecifies the style for displaying files using batfull
FZF_GIT_CATDefines the preview command used for displaying the filebat --style=$BAT_STYLE --color=$FZF_GIT_COLOR
FZF_GIT_COLORSet to never to suppress colors in the listalways
FZF_GIT_PAGERSpecifies the pager command for the preview window$(git config --get core.pager)
FZF_GIT_PREVIEW_COLORSet to never to suppress colors in the preview windowalways