]> Sergey Matveev's repositories - dotfiles.git/blob - tmux/bin/tmux-fzf.zsh
Split huge bin/ to proper subdirectories
[dotfiles.git] / tmux / bin / tmux-fzf.zsh
1 #!/usr/bin/env zsh
2
3 cd $2
4 set -e
5 tmp=`mktemp`
6 trap "rm -f $tmp" HUP PIPE INT QUIT TERM EXIT
7
8 case $1 in
9 (find)
10     bfs . -mindepth 1 \
11         -path "*/.git" -prune -o \
12         -path "*/.redo" -prune -o \
13         \( -type f -o -type d -o -type l \) -print |
14     cut -c3- | fzf -m --preview="less -N -S {}" |
15     while read fn ; do print ${(q)fn} ; done > $tmp
16     ;;
17 (buf-files)
18     tmux capture-pane -J
19     tmux save-buffer $tmp.capture
20     trap "rm -f $tmp.capture" HUP PIPE INT QUIT TERM EXIT
21     tmux delete-buffer
22     pe < $tmp.capture > $tmp
23     ;;
24 (git-files) git status --short | fzf -m | perl -npe 's/^\s*\S+\s+//' > $tmp ;;
25 (git-branches) { git branch ; git branch --remote } | fzf > $tmp ;;
26 (git-commits)
27     git --no-pager log --oneline -n 20 | perl -ne "print \"@~\$n \$_\"; \$n++" |
28     fzf --reverse | cut -w -f1 > $tmp
29     ;;
30 (*) echo unknown command ; sleep 1 ; exit ;;
31 esac
32
33 [ -s $tmp ] || exit
34 tmux set-buffer "`perl -npe 's/\n/ /g' $tmp`"
35 tmux paste-buffer
36 tmux delete-buffer