]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Huge tmux-fzf simplification with files quoting
authorSergey Matveev <stargrave@stargrave.org>
Sat, 27 Mar 2021 11:51:38 +0000 (14:51 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 27 Mar 2021 11:51:38 +0000 (14:51 +0300)
bin/bin/pe
bin/bin/tmux-fzf.sh [deleted file]
bin/bin/tmux-fzf.zsh [new file with mode: 0755]
tmux/.tmux.conf
zsh/.zshrc

index bcd149b25d6447add59254378258cabf9282243e..9777ecbde5c2309060dc423ca362c958b2b43630 100755 (executable)
@@ -5,5 +5,4 @@ path-extractor | while read fn ; do
     [[ $seen[$fn] -eq 1 ]] && continue
     seen+=($fn 1)
     print $fn
-done | fzf -m | tr "\n" " " | read data
-tmux set-buffer ${data:- }
+done | fzf -m
diff --git a/bin/bin/tmux-fzf.sh b/bin/bin/tmux-fzf.sh
deleted file mode 100755 (executable)
index 6333330..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
- #!/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-fzf.zsh b/bin/bin/tmux-fzf.zsh
new file mode 100755 (executable)
index 0000000..eb66b31
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env zsh
+
+cd $2
+set -e
+tmp=`mktemp`
+trap "rm -f $tmp" HUP PIPE INT QUIT TERM EXIT
+
+case $1 in
+(find)
+    find . -mindepth 1 -path "*/.git" -prune -o \
+        \( -type f -o -type d -o -type l \) -print |
+    cut -c3- | fzf -m --preview="less -N -S {}" |
+    while read fn ; do print ${(q)fn} ; done > $tmp
+    ;;
+(buf-files)
+    tmux capture-pane -J
+    tmux save-buffer $tmp.capture
+    trap "rm -f $tmp.capture" HUP PIPE INT QUIT TERM EXIT
+    tmux delete-buffer
+    pe < $tmp.capture > $tmp
+    ;;
+(git-files) git status --short | fzf -m | perl -npe 's/^\s*\S+\s+//' > $tmp ;;
+(git-branches) { git branch ; git branch --remote } | fzf > $tmp ;;
+(git-commits)
+    git --no-pager log --oneline -n 20 | perl -ne "print \"@~\$n \$_\"; \$n++" |
+    fzf --reverse | cut -w -f1 > $tmp
+    ;;
+(*) echo unknown command ; sleep 1 ; exit ;;
+esac
+
+[ -s $tmp ] || exit
+tmux set-buffer "`perl -npe 's/\n/ /g' $tmp`"
+tmux paste-buffer
+tmux delete-buffer
index 0ee677eb2903cdc33a8debb0101ba96e819e80e7..a3b7c072404a60a3cc224bddef7108d4a4c24868 100644 (file)
@@ -57,11 +57,11 @@ bind-key y {
 }
 
 bind-key o display-menu \
-    find o "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}'\""
+    find o "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.zsh find '#{pane_current_path}'\"" \
+    buf-files f "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.zsh buf-files '#{pane_current_path}'\"" \
+    git-files g "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.zsh git-files '#{pane_current_path}'\"" \
+    git-branches b "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.zsh git-branches '#{pane_current_path}'\"" \
+    git-commits c "display-popup -KE -w 100% -R \"~/bin/tmux-fzf.zsh git-commits '#{pane_current_path}'\""
 
 bind-key Y {
     capture-pane -J -S - -E -
index c8591ba5972046a12e51459d5fdbc643e5aeee06..b0c5e6a3c39af07fcc79d5a69a127cc33739248c 100644 (file)
@@ -213,7 +213,7 @@ ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
 # fzf {{{
 export FZF_DEFAULT_OPTS="--color=16 --info=inline"
 cf() {
-    local dir=$(find ${1:-.} -path "*/\.git" -prune -o -type d -print |
+    local dir=$(find ${1:-.} -mindepth 1 -path "*/\.git" -prune -o -type d -print |
         fzf --height 40% --reverse --preview="tree -CN {}")
     [[ -z $dir ]] || cd $dir
 }