]> Sergey Matveev's repositories - dotfiles.git/blob - bin/bin/tmux-fzf.zsh
Have not used zshfe for years
[dotfiles.git] / bin / 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     find . -mindepth 1 -path "*/.git" -prune -o \
11         \( -type f -o -type d -o -type l \) -print |
12     cut -c3- | fzf -m --preview="less -N -S {}" |
13     while read fn ; do print ${(q)fn} ; done > $tmp
14     ;;
15 (buf-files)
16     tmux capture-pane -J
17     tmux save-buffer $tmp.capture
18     trap "rm -f $tmp.capture" HUP PIPE INT QUIT TERM EXIT
19     tmux delete-buffer
20     pe < $tmp.capture > $tmp
21     ;;
22 (git-files) git status --short | fzf -m | perl -npe 's/^\s*\S+\s+//' > $tmp ;;
23 (git-branches) { git branch ; git branch --remote } | fzf > $tmp ;;
24 (git-commits)
25     git --no-pager log --oneline -n 20 | perl -ne "print \"@~\$n \$_\"; \$n++" |
26     fzf --reverse | cut -w -f1 > $tmp
27     ;;
28 (*) echo unknown command ; sleep 1 ; exit ;;
29 esac
30
31 [ -s $tmp ] || exit
32 tmux set-buffer "`perl -npe 's/\n/ /g' $tmp`"
33 tmux paste-buffer
34 tmux delete-buffer