Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imambungo/54481ed60fbf11e599fc1ab37677eee2 to your computer and use it in GitHub Desktop.
Save imambungo/54481ed60fbf11e599fc1ab37677eee2 to your computer and use it in GitHub Desktop.
Browsing git commit history with fzf
# https://gist.github.com/junegunn/f4fca918e937e6bf5bad#gistcomment-2731105
# my git log
mgl()
{
local the_git_log = 'git log --graph --pretty=format:"%C(bold blue)%s%C(auto)%d%n%C(yellow)%h%Creset %an, %C(magenta)%ar%Creset at %C(cyan)%ad%n%b" --date=format:"%H:%M" --author-date-order --all'
ggloga --color=always | \
fzf --ansi --no-sort --reverse --tiebreak=index --preview \
'source ~/.alias; f() { set -- $(echo -- "$@" | grep -o "[a-f0-9]\{7\}"); [ $# -eq 0 ] || git show --color=always $1 ; }; f \
"$(the_git_log | head -$(({n} + 2)) | tail -2)"' \
--bind 'ctrl-j:preview-down,ctrl-k:preview-up,alt-j:preview-page-down,alt-k:preview-page-up,ctrl-m:execute: \
(git log --graph --pretty=format:"%C(bold blue)%s%C(auto)%d%n%C(yellow)%h%Creset %an, %C(magenta)%ar%Creset at %C(cyan)%ad%n%b" --date=format:"%H:%M" --author-date-order --all | head -$(({n} +2)) | tail -2 | grep -o "[a-f0-9]\{7\}" | head -1 |
xargs -I % sh -c "git show --color=always % | less -R") << "FZF-EOF"
{}
FZF-EOF' --preview-window=right:60%
}
@imambungo
Copy link
Author

imambungo commented Mar 24, 2020

Keybind:

  • ctrl-p = previous
  • ctrl-n = next
  • ctrl-k = preview up
  • ctrl-j = preview down
  • alt-k = preview page up
  • alt-j = preview page down

Screenshot:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment