## Author: druckdev ## Created: 2020-08-28 ## ## A TUI for git-log using fzf. ## Displays git-log in fzf and git-show as preview command for each commit. # extendedglob is necessary for the expansion of the binds array emulate -L zsh -o extendedglob # 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' # Verbose format for the preview window on the right # This array is stitched together with newlines later local -a format=( '--pretty=format:%C(yellow)' # newline created by this eaten by %- '%-commit: %H%C(auto)' # yellow commit hash '%-D%Cblue' # auto colored ref names (if any) 'Author: %aN %aE%Cred' # blue author mail 'AuthorDate: %ad%Cblue' # red author date 'Commit: %cN %cE%Cred' # blue commiter mail 'CommitDate: %cd%Creset%C(bold)' # red commit date '' ' %s%Creset' # bold white subject ' ' # space is here so that the empty line is not eaten when empty body '%-b' # body ) # Before being able to operate on the string itself we need to remove all ansi # color escape sequences to not confuse sed. (see git show below) local del_ansi='s/\[[0-9]{0,2}m//g' # Ignore the graph part at the beginning, then capture the commit hash and throw # away the rest of the line. local commit_hash='s/^[ */\\|]*([a-f0-9]+).*$/\1/' local dateshort='--date=format:%F' # year local date='--date=format:%F %T %z' # year time timezone local colors='--color=always' local fzf_preview_command read -r -d '' fzf_preview_command <