-
-
Save abaldwin88/8acf2bb98680add4fca99c7b9215774c to your computer and use it in GitHub Desktop.
fzf + git stash
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
fstash() { | |
local out q k sha | |
while out=$( | |
git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" | | |
fzf --ansi --no-sort --query="$q" --print-query \ | |
--expect=ctrl-d,ctrl-b); | |
do | |
IFS=$'\n'; set -f | |
lines=($(<<< "$out")) | |
unset IFS; set +f | |
q="${lines[0]}" | |
k="${lines[1]}" | |
sha="${lines[-1]}" | |
sha="${sha%% *}" | |
[[ -z "$sha" ]] && continue | |
if [[ "$k" == 'ctrl-d' ]]; then | |
git diff $sha | |
elif [[ "$k" == 'ctrl-b' ]]; then | |
git stash apply $sha | |
break; | |
else | |
git -c color.ui=always stash show -p $sha | less -+F | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment