Skip to content

Instantly share code, notes, and snippets.

@abaldwin88
Forked from dekz/fstash.zsh
Last active March 31, 2017 21:45
Show Gist options
  • Save abaldwin88/8acf2bb98680add4fca99c7b9215774c to your computer and use it in GitHub Desktop.
Save abaldwin88/8acf2bb98680add4fca99c7b9215774c 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 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