]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Single tmux popup for fzf
authorSergey Matveev <stargrave@stargrave.org>
Wed, 10 Feb 2021 10:29:11 +0000 (13:29 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 10 Feb 2021 10:37:30 +0000 (13:37 +0300)
bin/bin/pe
bin/bin/tmux-fzf.sh [new file with mode: 0755]
bin/bin/tmux-path-extractor.sh [deleted file]
tmux/.tmux.conf
zsh/.zshrc

index 77c87900af33164db4a2c53cefe4ba53432c3bcd..48b7ededf422428d9ed72ed41d9f7fe4a8c4a452 100755 (executable)
@@ -6,4 +6,4 @@ path-extractor | while read fn ; do
     seen+=($fn 1)
     print $fn
 done | fzf -m | tr "\n" " " | read data
     seen+=($fn 1)
     print $fn
 done | fzf -m | tr "\n" " " | read data
-tmux set-buffer "$data"
+tmux set-buffer "${data:- }"
diff --git a/bin/bin/tmux-fzf.sh b/bin/bin/tmux-fzf.sh
new file mode 100755 (executable)
index 0000000..6333330
--- /dev/null
@@ -0,0 +1,54 @@
+ #!/bin/sh
+
+tmux capture-pane -J
+tmp=`mktemp`
+trap "rm -f $tmp" HUP PIPE INT QUIT TERM EXIT
+tmux save-buffer $tmp
+tmux delete-buffer
+session_name="fzf-selector"
+tmux has-session -t $session_name 2>/dev/null && tmux kill-session -t $session_name || :
+
+case "$1" in
+find)
+    tmux new-session -d -s $session_name -c "$2" '
+        find . -path "*/.git" -prune -o \( -type f -o -type d -o -type l \) -print |
+        cut -c3- | fzf -m --preview="less -N -S {}" | read data
+        tmux set-buffer "${data:- }"
+    '
+    ;;
+buf-files)
+    tmux new-session -d -s $session_name -c "$2" "pe < $tmp"
+    ;;
+git-files)
+    tmux new-session -d -s $session_name -c "$2" '
+        git status --short | fzf -m | while read item ; do
+            item=$(echo $item | cut -w -f2-)
+            echo -n "$item "
+        done | read data
+        tmux set-buffer "${data:- }"
+    '
+    ;;
+git-branches)
+    tmux new-session -d -s $session_name -c "$2" '
+        { git branch ; git branch --remote } | fzf | read data
+        tmux set-buffer "${data:- }"
+    '
+    ;;
+git-commits)
+    tmux new-session -d -s $session_name -c "$2" '
+        git --no-pager log --oneline -n 20 | perl -ne "print \"@~\$n \$_\"; \$n++" |
+        fzf --reverse | cut -w -f1 | read data
+        tmux set-buffer "${data:- }"
+    '
+    ;;
+*)
+    echo unknown command
+    sleep 1
+    exit
+    ;;
+esac
+
+tmux set-option -t $session_name status off
+tmux attach-session -t $session_name
+tmux paste-buffer
+tmux delete-buffer
diff --git a/bin/bin/tmux-path-extractor.sh b/bin/bin/tmux-path-extractor.sh
deleted file mode 100755 (executable)
index ed2cebc..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-tmux has-session -t path-extractor && tmux kill-session -t path-extractor || :
-tmux new-session -d -s path-extractor -c "$1" "pe < /tmp/tmux-buffer ; tmux detach"
-tmux set-option -t path-extractor status off
-exec tmux attach-session -t path-extractor
index db063c9658656f5ae4b0294eee1acdd46c528513..da27feaaa8cff4940d200007d09b330acf541f77 100644 (file)
@@ -56,20 +56,12 @@ bind-key y {
     split-window 'vim -c "set listchars=" -c "match ExtraWhitespace //" /tmp/tmux-buffer'
 }
 
     split-window 'vim -c "set listchars=" -c "match ExtraWhitespace //" /tmp/tmux-buffer'
 }
 
-bind-key o {
-    capture-pane -J
-    save-buffer /tmp/tmux-buffer
-    delete-buffer
-    display-popup -KE -w 100% -R "~/bin/tmux-path-extractor.sh '#{pane_current_path}'"
-    paste-buffer
-    delete-buffer
-}
-
-bind-key O {
-    display-popup -KE -w 100% -R "~/bin/tmux-git-extractor.sh '#{pane_current_path}'"
-    paste-buffer
-    delete-buffer
-}
+bind-key o display-menu \
+    find d "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.sh find '#{pane_current_path}'\"" \
+    buf-files f "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.sh buf-files '#{pane_current_path}'\"" \
+    git-files g "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.sh git-files '#{pane_current_path}'\"" \
+    git-branches b "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.sh git-branches '#{pane_current_path}'\"" \
+    git-commits c "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.sh git-commits '#{pane_current_path}'\""
 
 bind-key Y {
     capture-pane -J -S - -E -
 
 bind-key Y {
     capture-pane -J -S - -E -
index cede543bcdc428b2619810e2c6b52bb67038f961..387f852f7dca9ef012c07f50bc9079a5e2054db1 100644 (file)
@@ -211,17 +211,10 @@ ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
 # }}}
 
 # fzf {{{
 # }}}
 
 # fzf {{{
-alias -g PE="| pe"
-
-export FZF_DEFAULT_OPTS="--color=16 --info=inline --preview='less -N -S {}'"
-
-_fzf_find() {
-    find . \( -path "*/\.git" -o -fstype devfs -o -fstype procfs \) -prune \
-        -o \( -type d $@ \) -print 2>/dev/null | cut -b3-
+export FZF_DEFAULT_OPTS="--color=16 --info=inline"
+cf() {
+    local dir=$(find ${1:-.} -path "*/\.git" -prune -o -type d -print |
+        fzf --height 40% --reverse --preview="tree -CN {}")
+    [[ -z "$dir" ]] || cd "$dir"
 }
 }
-
-export FZF_CTRL_T_COMMAND="_fzf_find -o -type f -o -type l"
-export FZF_ALT_C_COMMAND=_fzf_find
-
-. ~/work/fzf/shell/key-bindings.zsh
 # }}}
 # }}}