Support fzf-tmux when zoomed

This commit is contained in:
Pokey Rule 2015-12-07 17:45:22 -08:00
parent a1db64e7b1
commit d513a210c6
2 changed files with 19 additions and 7 deletions

View File

@ -82,11 +82,19 @@ while [ $# -gt 0 ]; do
shift shift
done done
if [ -z "$TMUX_PANE" ] || tmux list-panes -F '#F' | grep -q Z; then if [ -z "$TMUX_PANE" ]; then
fzf "${args[@]}" fzf "${args[@]}"
exit $? exit $?
fi fi
# Handle zoomed tmux pane by moving it to a temp window
if tmux list-panes -F '#F' | grep -q Z; then
zoomed=1
original_window=$(tmux display-message -p "#{window_id}")
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - \\\\; do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
fi
set -e set -e
# Clean up named pipes on exit # Clean up named pipes on exit
@ -97,6 +105,14 @@ fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id" fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
cleanup() { cleanup() {
rm -f $argsf $fifo1 $fifo2 $fifo3 rm -f $argsf $fifo1 $fifo2 $fifo3
# Remove temp window if we were zoomed
if [ -n "$zoomed" ]; then
tmux swap-pane -t $original_window \; \
select-window -t $original_window \; \
kill-window -t $tmp_window \; \
resize-pane -Z
fi
} }
trap cleanup EXIT SIGINT SIGTERM trap cleanup EXIT SIGINT SIGTERM

View File

@ -52,17 +52,13 @@ function! s:fzf_exec()
return s:exec return s:exec
endfunction endfunction
function! s:tmux_not_zoomed()
return system('tmux list-panes -F "#F"') !~# 'Z'
endfunction
function! s:tmux_enabled() function! s:tmux_enabled()
if has('gui_running') if has('gui_running')
return 0 return 0
endif endif
if exists('s:tmux') if exists('s:tmux')
return s:tmux && s:tmux_not_zoomed() return s:tmux
endif endif
let s:tmux = 0 let s:tmux = 0
@ -70,7 +66,7 @@ function! s:tmux_enabled()
let output = system('tmux -V') let output = system('tmux -V')
let s:tmux = !v:shell_error && output >= 'tmux 1.7' let s:tmux = !v:shell_error && output >= 'tmux 1.7'
endif endif
return s:tmux && s:tmux_not_zoomed() return s:tmux
endfunction endfunction
function! s:shellesc(arg) function! s:shellesc(arg)