summary refs log tree commit diff
path: root/bin/fzfez
blob: 708091232ce49c4c9492c48389c733cc73d33d0a (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
67
68
69
70
71
72
73
74
75
76
#!/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)' \
			| cut -d' ' -f1 \
			| sed 's#^refs/##' \
			| sed 's#^remotes/##' \
			| sed 's#^heads/##' \
			| $0 \
				--ansi --no-sort --reverse --tac \
				--header 'Press ctrl-s to toggle sort' \
				--bind 'ctrl-s:toggle-sort' \
				--preview 'git log --color=always --oneline --graph --date=short {} | head -${LINES}' \
				--preview-window right:70% \
				--bind "ctrl-o:execute(git checkout {})"
		;;

	git-tags)
		git rev-parse HEAD > /dev/null 2>&1 || exit 1
		  git tag --sort -version:refname \
			| cut -d' ' -f1 \
			| sed 's#^refs/##' \
			| sed 's#^remotes/##' \
			| sed 's#^heads/##' \
			| $0 \
				--ansi --no-sort --reverse \
				--preview 'git show --color=always {} | head -${LINES}' \
				--preview-window right:70%
		;;

	git-log)
		git log --color=always --oneline \
			| $0 \
				--ansi --no-sort --reverse \
				--preview 'echo {} | cut -d\  -f1 | xargs git show --color=always --pretty=full --stat --patch' \
				--preview-window right:50% \
			| cut -d' ' -f1 \
			| xargs -i git log -1 --pretty=%H {}
		;;

	rg)
		shift
		rg $@ --files-with-matches \
			| $0 \
				--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