From 1ce6c323a3c4f76c45bedbaf642661c1b65a59f9 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 30 Apr 2018 21:50:22 +0200 Subject: [PATCH 1/2] Refactor s:TmuxCommand, add s:GetTmuxCommand - use a list instead of single string - add s:GetTmuxCommand to be used later when not using `system()` only - remove `:silent` when calling tmux from `s:TmuxAwareNavigate`: it should not be necessary and is bad practice to use `:silent` unnecessarily. It was added in b068a04 with no explanation. --- plugin/tmux_navigator.vim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin/tmux_navigator.vim b/plugin/tmux_navigator.vim index 7a91117..2a398ef 100644 --- a/plugin/tmux_navigator.vim +++ b/plugin/tmux_navigator.vim @@ -28,7 +28,7 @@ function! s:InTmuxSession() endfunction function! s:TmuxVimPaneIsZoomed() - return s:TmuxCommand("display-message -p '#{window_zoomed_flag}'") == 1 + return s:TmuxCommand(['display-message', '-p', '#{window_zoomed_flag}']) == 1 endfunction function! s:TmuxSocket() @@ -36,13 +36,17 @@ function! s:TmuxSocket() return split($TMUX, ',')[0] endfunction +function! s:GetTmuxCommand(args) + return [s:TmuxOrTmateExecutable(), '-S', s:TmuxSocket()] + a:args +endfunction + function! s:TmuxCommand(args) - let cmd = s:TmuxOrTmateExecutable() . ' -S ' . s:TmuxSocket() . ' ' . a:args - return system(cmd) + let cmd = s:GetTmuxCommand(a:args) + return substitute(system(cmd), '\n$', '', '') endfunction function! s:TmuxPaneCurrentCommand() - echo s:TmuxCommand("display-message -p '#{pane_current_command}'") + echo s:TmuxCommand(['display-message', '-p', '#{pane_current_command}']) endfunction command! TmuxPaneCurrentCommand call s:TmuxPaneCurrentCommand() @@ -94,8 +98,8 @@ function! s:TmuxAwareNavigate(direction) catch /^Vim\%((\a\+)\)\=:E141/ " catches the no file name error endtry endif - let args = 'select-pane -t ' . shellescape($TMUX_PANE) . ' -' . tr(a:direction, 'phjkl', 'lLDUR') - silent call s:TmuxCommand(args) + let args = ['select-pane', '-t', $TMUX_PANE, '-'.tr(a:direction, 'phjkl', 'lLDUR')] + call s:TmuxCommand(args) if s:NeedsVitalityRedraw() redraw! endif From 2eb16d5dbf2b3366041c1ee7e48616bd144140ec Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 16 May 2018 23:21:36 +0200 Subject: [PATCH 2/2] fixup! Refactor s:TmuxCommand, add s:GetTmuxCommand --- plugin/tmux_navigator.vim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugin/tmux_navigator.vim b/plugin/tmux_navigator.vim index 2a398ef..b6bc664 100644 --- a/plugin/tmux_navigator.vim +++ b/plugin/tmux_navigator.vim @@ -40,10 +40,17 @@ function! s:GetTmuxCommand(args) return [s:TmuxOrTmateExecutable(), '-S', s:TmuxSocket()] + a:args endfunction -function! s:TmuxCommand(args) - let cmd = s:GetTmuxCommand(a:args) - return substitute(system(cmd), '\n$', '', '') -endfunction +if has('nvim') + function! s:TmuxCommand(args) + return substitute(system(s:GetTmuxCommand(a:args)), '\n$', '', '') + endfunction +else + function! s:TmuxCommand(args) + " Vim does not support a list for `system()`. + let cmd = join(map(s:GetTmuxCommand(a:args), 'fnameescape(v:val)')) + return substitute(system(cmd), '\n$', '', '') + endfunction +endif function! s:TmuxPaneCurrentCommand() echo s:TmuxCommand(['display-message', '-p', '#{pane_current_command}'])