Skip to content

Instantly share code, notes, and snippets.

@lamchau
Created May 20, 2020 08:16
Show Gist options
  • Save lamchau/872a31b076ade2821d8be8b7859876b5 to your computer and use it in GitHub Desktop.
Save lamchau/872a31b076ade2821d8be8b7859876b5 to your computer and use it in GitHub Desktop.
git log + fzf + delta => returns git_sha
# ported from https://github.com/junegunn/fzf/wiki/examples#git
function glog --description 'git log + fzf + delta => returns git_sha'
set -lx git_dir (git rev-parse --git-dir 2> /dev/null)
if test -n "$git_dir"
set -l EXTRACTED_SHA "echo {} | head -1 | cut -d' ' -f1"
set -l VIEW_LINE "$EXTRACTED_SHA | xargs -I % sh -c 'git show --color=always % | delta'"
set -l FORMAT "%C(auto)%h%d %s %C(black)%C(bold)%cr% C(auto)%aE"
set -l commit_sha (git log --color=always --format="$FORMAT" $argv \
| fzf --no-sort --reverse --tiebreak=index --no-multi --ansi --preview="$VIEW_LINE" \
| cut -d' ' -f1)
if test -n "$commit_sha"
echo $commit_sha
end
else
echo "'$PWD' is not a git repository"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment