-
-
Save jeebak/58ce004182830b808e75 to your computer and use it in GitHub Desktop.
Browsing git commit history with fzf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://junegunn.kr/2015/03/browsing-git-commits-with-fzf/ | |
# https://gist.github.com/junegunn/f4fca918e937e6bf5bad | |
# fshow - git commit browser (enter for show, ctrl-d for diff, ` toggles sort) | |
fzf-git-show() { | |
local out shas sha q k | |
if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then | |
while out=$( | |
git log --graph --color=always \ | |
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" | | |
fzf --ansi --multi --no-sort --reverse --query="$q" \ | |
--print-query \ | |
--expect=ctrl-d,ctrl-l,ctrl-n \ | |
--toggle-sort=\`); do | |
q=$(head -1 <<< "$out") | |
k=$(head -2 <<< "$out" | tail -1) | |
shas=$(sed '1,2d;s/^[^a-z0-9]*//;/^$/d' <<< "$out" | awk '{print $1}') | |
[[ -z "$shas" ]] && continue | |
case "$k" in | |
ctrl-d) | |
git diff --color=always $shas | less -R;; | |
ctrl-l) | |
git log -p --color=always ${shas}.. | less -R;; | |
ctrl-n) | |
git show --name-status --color=always ${shas} | less -R;; | |
*) | |
for sha in $shas; do | |
git show --color=always $sha | less -R | |
done | |
;; | |
esac | |
done | |
else | |
echo -e "Not a git repo" | |
fi | |
zle accept-line | |
} | |
zle -N fzf-git-show | |
bindkey '\eq' fzf-git-show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment