-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfstash
executable file
·36 lines (33 loc) · 1.29 KB
/
fstash
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
#!/usr/bin/env zsh
while out=$(git stash list "$@" |
fzf --ansi --no-sort --reverse --print-query --query="$query" \
--expect=ctrl-m,ctrl-b,del \
--preview-window=bottom:60% \
--preview 'git show --patience --stat --pretty=oneline --color=always \
-p (echo {} | cut -d: -f1 | less -R)' \
# ^^ dropped quotes and changed $( to ( for fish subshell. ick.
);
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
# enter or ctrl-m is just a diff
ctrl-m)
git diff --patience --color=always -p "$reflog_selector" | less -R
;;
# ctrl-b checks out the stash as a branch and removes the stash
ctrl-b)
sha=$(echo "$selection[3]" | grep -o '[a-f0-9]\{7\}')
git stash branch "stash-$sha" "$reflog_selector"
break
;;
# del will drop the stash
del)
git stash drop "$reflog_selector"
;;
esac
done