Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor s:TmuxCommand, add s:GetTmuxCommand #200

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions plugin/tmux_navigator.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,32 @@ 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()
" The socket path is the first value in the comma-separated list of $TMUX.
return split($TMUX, ',')[0]
endfunction

function! s:TmuxCommand(args)
let cmd = s:TmuxOrTmateExecutable() . ' -S ' . s:TmuxSocket() . ' ' . a:args
return system(cmd)
function! s:GetTmuxCommand(args)
return [s:TmuxOrTmateExecutable(), '-S', s:TmuxSocket()] + a:args
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}'")
echo s:TmuxCommand(['display-message', '-p', '#{pane_current_command}'])
endfunction
command! TmuxPaneCurrentCommand call s:TmuxPaneCurrentCommand()

Expand Down Expand Up @@ -94,8 +105,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
Expand Down