-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-stash-explore
executable file
·44 lines (40 loc) · 1.56 KB
/
git-stash-explore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env zsh
while out=$(git stash list "$@" |
fzf --ansi --no-sort --reverse --print-query --query="$query" \
--expect=ctrl-a,ctrl-b,ctrl-p,del \
--bind="ctrl-u:preview-page-up" \
--bind="ctrl-d:preview-page-down" \
--bind="ctrl-k:preview-up" \
--bind="ctrl-j:preview-down" \
--preview="echo {} | cut -d':' -f1 | xargs git stash show -p" \
--preview-window='down:85%');
do
# Tokenize selection by newline
selection=("${(f)out}")
# Keep the query accross fzf calls
query="$selection[1]"
# Represents the stash, e.g. stash{1}
reflog_selector=$(echo "$selection[3]" | cut -d ':' -f 1)
case "$selection[2]" in
# ctrl-a applies the stash to the current tree
ctrl-a)
git stash apply "$reflog_selector"
break
;;
# ctrl-b checks out the stash as a branch
ctrl-b)
sha=$(echo "$selection[3]" | grep -o '[a-f0-9]\{7\}')
git stash branch "stash-$sha" "$reflog_selector"
break
;;
# ctrl-p is like ctrl-a but it drops the stash. Uses stash pop.
ctrl-p)
git stash pop "$reflog_selector"
break
;;
# del will drop the stash
del)
git stash drop "$reflog_selector"
;;
esac
done