blob: 11910525597a52b9004b15ff735b7cb0b4f2da29 (
plain) (
blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/bin/sh
set -e
exec_hist=/tmp/fzf-interactive_exec-hist
if [ ! -f "$exec_hist" ]; then
touch "$exec_hist"
fi
case "$1" in
exec)
uniq "$exec_hist" \
| grep -v '^$' \
| fzf \
--header 'Select or enter a command, {} is previous selection' \
--bind 'tab:replace-query' \
--bind 'enter:print-query' \
| tee -a $exec_hist \
| sed "s#{}#$2#g" \
| sh -s
exit $?
;;
git-branches)
git rev-parse HEAD > /dev/null 2>&1 || exit 1
git branch -a --sort=refname --format='%(refname)' \
| $0 \
--border --ansi --no-sort --reverse --tac \
--header 'Press ctrl-s to toggle sort' \
--bind 'ctrl-s:toggle-sort' \
--preview 'git log --oneline --graph --date=short --color=always {} | head -${LINES}' \
--preview-window right:70% \
| cut -d' ' -f1 \
| sed 's#^refs/##' \
| sed 's#^remotes/##' \
| sed 's#^heads/##'
;;
git-tags)
git rev-parse HEAD > /dev/null 2>&1 || exit 1
git tag --sort -version:refname \
| $0 \
--border --no-sort \
--preview 'git show --color=always {} | head -${LINES}' \
--preview-window right:70% \
| cut -d' ' -f1 \
| sed 's#^refs/##' \
| sed 's#^remotes/##' \
| sed 's#^heads/##'
;;
rg)
shift
rg $@ --files-with-matches \
| $0 \
--border \
--header 'Press ctrl-s to toggle sort' \
--bind 'ctrl-s:toggle-sort' \
--preview "rg $* --color=always --no-filename --glob='{}' --context=5 --line-number"
;;
*)
fzf \
--bind "ctrl-x:execute(${0} exec {})" \
"$@" ;;
esac
|