Created
May 20, 2020 08:16
-
-
Save lamchau/872a31b076ade2821d8be8b7859876b5 to your computer and use it in GitHub Desktop.
git log + fzf + delta => returns git_sha
This file contains hidden or 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
# 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