Skip to content

Instantly share code, notes, and snippets.

@dekz
Last active April 12, 2023 00:15
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dekz/9c22ba1f86edc744c8b17561257a5df0 to your computer and use it in GitHub Desktop.
Save dekz/9c22ba1f86edc744c8b17561257a5df0 to your computer and use it in GitHub Desktop.
fzf + git stash
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 branch "stash-$sha" $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