#!/usr/bin/env zsh ## Author: druckdev ## Created: 2021-05-15 ## ## A TUI for displaying branches using fzf. ## Displays `git branch -a` in fzf and git-log as preview for each branch. # extendedglob is necessary for the expansion of the binds array emulate -L zsh -o extendedglob # Return if fzf is not available if (( ! $+commands[fzf] )); then printf "command not found: fzf" >&2 return 1 fi # Return if not in git repo git rev-parse || return # One line format for fzf list view # abbreviated commit hash (yellow), title and ref names local formatshort='--pretty=format:%C(yellow)%h %Creset%s%C(auto)%d' local dateshort='--date=format:%F' # year local date="$dateshort %T %z" # year time timezone local -A fzf_preview read -r -d '' </dev/null)}) if (( ! $? )) && (( $tty_size[2] * 0.4 > $tty_size[1] )); then fzf_args+=(--preview-window=right) else fzf_args+=(--preview-window=down) fi # Display an ascii graph of the commits in the above format and pipe that into # fzf. git branch -a --color=always "$@" \ | fzf "${fzf_args[@]}" return 0