fzfgit scripts

This is a fork of dotbare. The scripts are modified to work with a regular git directory.

Installation:

Manual - use as a script

git clone https://github.com/lmburns/fzfgit.git
cd fzfgit
make install

zsh

zinit

zinit light lmburns/fzfgit

oh-my-zsh

git clone https://github.com/lmburns/fzfgit.git ${ZDOTDIR:-$HOME}/.oh-my-zsh/custom/plugins/fzfgit

# Add to .zshrc
plugins=( fzfgit )

Antigen

antigen bundle lmburns/fzfgit

Manual - use as a zsh plugin

git clone https://github.com/lmburns/fzfgit.git ${ZDOTDIR:-$HOME}/.fzfgit

# Add to .zshrc
source "${ZDOTDIR:-$HOME}/.fzfgit"

Dependencies:

# macOS installation - linux distributions should have it in their package manager
# if not, check the links above to download from Github
brew install fzf bat delta exa

Scripts

fadd

Select files/directories or modified files through fzf and stage the selected files/directories.

fcheckout

Checkout files/commit/branch interactively through fzf.

fedit

Select files/commits through fzf and edit selected files/commits in $EDITOR. Editing commits will perform a interactive rebase.

flog

Interactive log viewer that will prompt you with a menu after selecting a commit. The action menu contains options including edit, reset, revert and checkout the selected commits.

freset

Select staged files or commits through fzf and then reset(unstage) staged files or reset HEAD back to certain commits. Also supports reset HEAD back to certain commits using either --soft, --hard, --mixed flags. More information on differences between flags here.

fstash

View and manage stash interactively.

fstat

Display interactive git status menu. Toggle file stage/unstage status interactively.

funtrack

Stop tracking the selected git files. It could also be used to temporarily stop tracking changes for files and then later on resume tracking changes.

Note: This command has severe limitations.

By default, selected files are permanently untracked from git. Selected files will be remove from index while keeping the file in your current system. However, when your other machines pull down the changes, the untracked files will be deleted by git. This is a limitation with git.

funtrack does come with capabilities to temporarily untrack files, which will not remove the untracked files from other system. However, this is NOT recommended way to untrack files, explained here.

fzgrep

Grep words within tracked files and select to edit them through fzf. The words are listed as lines in fzf and is separated by columns. First column is the file name, second column is the line number and the third column and beyond are the content of the lines.

Helper scripts

fgit_helper.sh

Provides variables and functions used by some of the scripts mentioned above.

preview.sh

Fzf preview window coloring.

Environment variables

FZFGIT_DEFAULT_OPTS

Enable alternate options for this specific use of fzf. Not set by default.

export FZFGIT_DEFAULT_OPTS="--preview-window=':nohidden,right:65%:wrap'"

FZFGIT_KEY

Set default keybindings for all the fzf commands. See man fzf for a list of all possible options, or here.

# This variable does have a default value
export FZFGIT_KEY="
  --bind='ctrl-a:toggle-all'                            # toggle all selection
  --bind='ctrl-b:execute(bat --paging=always -f {+})'   # open in a pager
  --bind='ctrl-y:execute-silent(echo {+} | pbcopy)'     # copy the file to clipboard
  --bind='ctrl-e:execute(echo {+} | xargs -o $EDITOR)'  # open file in editor
  --bind='ctrl-k:preview-up'                            # move the file preview up
  --bind='ctrl-j:preview-down'                          # move the file preview down
  --bind='alt-j:jump'                                   # label jump mode, sort of like vim-easymotion
  --bind='ctrl-0:top'                                   # set cursor back to top
  --bind='ctrl-s:toggle-sort'                           # toggle sorting
  --bind='?:toggle-preview'                             # toggle preview
"

FZFGIT_PREVIEW

Preview command for the preview window in fzf. The order in which the preview is determined is: bat, highlight, coderay, rougify, cat. Not set by default.

# Two different ones are given as examples to display the complexity it can be
# When specifying the command, be sure to use the {} placeholder
export FZFGIT_PREVIEW="([[ -f {} ]] && (bat --style=numbers --color=always {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200"

export FZFGIT_PREVIEW="cat -n {}"

FZFGIT_DIFF_PAGER

Customize diff preview on commands that display diff output. The initial value is read from from git config core.pager. Use this to specify something different.

export FZFGIT_DIFF_PAGER="delta --diff-so-fancy --line-numbers"

FZFGIT_BACKUP

Top level directory where the current directory you are in can be backed up to. I am working on allowing specification of a path to a directory that you're currently not in.

export FZFGIT_BACKUP="{$XDG_DATA_HOME}/gitbackup"