Skip to content

Instantly share code, notes, and snippets.

@lamchau
Created May 19, 2020 11:20
Show Gist options
  • Save lamchau/93010c4959120a76f2612ec4cdb8caab to your computer and use it in GitHub Desktop.
Save lamchau/93010c4959120a76f2612ec4cdb8caab to your computer and use it in GitHub Desktop.
browsable git log (requires `fzf` `delta`)
#!/usr/bin/env bash
# derived from https://github.com/junegunn/fzf/wiki/examples#git
glog() {
# extra sha from git log
local parse_log="echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
# pass log line into colorized diff `delta`
# https://github.com/dandavison/delta
local view_line="$parse_log | xargs -I % sh -c 'git show --color=always % | delta'"
# https://github.com/koalaman/shellcheck/wiki/SC2155
local commit_sha
commit_sha=$(git log --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr% C(auto)%an" "$@" |
fzf --no-sort --reverse --tiebreak=index --no-multi --ansi --preview="$view_line" |
cut -d' ' -f1)
# strip whitespace, if selecting a file before fzf completes, there's
# a leading whitespace
commit_sha="${commit_sha// /}"
if [ -n "$commit_sha" ]; then
echo "$commit_sha"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment