Created
July 21, 2016 05:03
-
-
Save junegunn/a563d9e3e07fd721d618562762ec619d to your computer and use it in GitHub Desktop.
gstash
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
gstash() { | |
local out k reflog | |
out=( | |
$(git stash list --pretty='%C(yellow)%gd %>(14)%Cgreen%cr %C(blue)%gs' | | |
fzf --ansi --no-sort --header='enter:show, ctrl-d:diff, ctrl-o:pop, ctrl-y:apply, ctrl-x:drop' \ | |
--preview='git stash show --color=always -p $(cut -d" " -f1 <<< {}) | head -'$LINES \ | |
--preview-window=down:50% --reverse \ | |
--bind='enter:execute(git stash show --color=always -p $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \ | |
--bind='ctrl-d:execute(git diff --color=always $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \ | |
--expect=ctrl-o,ctrl-y,ctrl-x)) | |
k=${out[0]} | |
reflog=${out[1]} | |
[ -n "$reflog" ] && case "$k" in | |
ctrl-o) git stash pop $reflog ;; | |
ctrl-y) git stash apply $reflog ;; | |
ctrl-x) git stash drop $reflog ;; | |
esac | |
} |
This is amazing. Thank you!
I had to make a minor fix:
- k=${out[0]}
- reflog=${out[1]}
+ k=${out[1]}
+ reflog=${out[2]}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍