From d513a210c6b59106d899c8e3287e24a3ffc5956d Mon Sep 17 00:00:00 2001
From: Pokey Rule <pokey.rule@gmail.com>
Date: Mon, 7 Dec 2015 17:45:22 -0800
Subject: [PATCH] Support fzf-tmux when zoomed

---
 bin/fzf-tmux   | 18 +++++++++++++++++-
 plugin/fzf.vim |  8 ++------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/bin/fzf-tmux b/bin/fzf-tmux
index 1085b963..f882f8c5 100755
--- a/bin/fzf-tmux
+++ b/bin/fzf-tmux
@@ -82,11 +82,19 @@ while [ $# -gt 0 ]; do
   shift
 done
 
-if [ -z "$TMUX_PANE" ] || tmux list-panes -F '#F' | grep -q Z; then
+if [ -z "$TMUX_PANE" ]; then
   fzf "${args[@]}"
   exit $?
 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
 
 # Clean up named pipes on exit
@@ -97,6 +105,14 @@ fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
 fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
 cleanup() {
   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
 
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index fddab518..d8106935 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -52,17 +52,13 @@ function! s:fzf_exec()
   return s:exec
 endfunction
 
-function! s:tmux_not_zoomed()
-  return system('tmux list-panes -F "#F"') !~# 'Z'
-endfunction
-
 function! s:tmux_enabled()
   if has('gui_running')
     return 0
   endif
 
   if exists('s:tmux')
-    return s:tmux && s:tmux_not_zoomed()
+    return s:tmux
   endif
 
   let s:tmux = 0
@@ -70,7 +66,7 @@ function! s:tmux_enabled()
     let output = system('tmux -V')
     let s:tmux = !v:shell_error && output >= 'tmux 1.7'
   endif
-  return s:tmux && s:tmux_not_zoomed()
+  return s:tmux
 endfunction
 
 function! s:shellesc(arg)
-- 
GitLab