Prevent killing the Vim pane

If the user has swapped the pane layout, it is possible that VTR could
attempt to kill the Vim pane. This introduces a sanity check that
prevents killing the active / Vim pane.

Closes #7 - Protect against killing Vim pane
This commit is contained in:
Chris Toomey 2014-11-14 16:41:59 -05:00
parent 1be6d62b51
commit e05b373ff3

View File

@ -68,9 +68,13 @@ function! s:RequireLocalPaneOrDetached()
endfunction endfunction
function! s:KillLocalRunner() function! s:KillLocalRunner()
if s:runner_pane == s:ActiveTmuxPaneNumber()
call s:EchoError("RunnerPane is set to current pane. Cancelling")
else
let targeted_cmd = s:TargetedTmuxCommand("kill-pane", s:runner_pane) let targeted_cmd = s:TargetedTmuxCommand("kill-pane", s:runner_pane)
call s:SendTmuxCommand(targeted_cmd) call s:SendTmuxCommand(targeted_cmd)
unlet s:runner_pane unlet s:runner_pane
endif
endfunction endfunction
function! s:KillDetachedWindow() function! s:KillDetachedWindow()
@ -91,11 +95,7 @@ function! s:KillRunnerPane()
endfunction endfunction
function! s:ActiveTmuxPaneNumber() function! s:ActiveTmuxPaneNumber()
for pane_title in s:TmuxPanes() return s:SendTmuxCommand("display-message -p \"#{pane_index}\"")
if pane_title =~ '\(active\)'
return pane_title[0]
endif
endfor
endfunction endfunction
function! s:TmuxPanes() function! s:TmuxPanes()
@ -133,9 +133,13 @@ function! s:ZoomRunnerPane()
call s:SendTmuxCommand(resize_cmd) call s:SendTmuxCommand(resize_cmd)
endfunction endfunction
function! s:Strip(string)
return substitute(a:string, '^\s*\(.\{-}\)\s*$', '\1', '')
endfunction
function! s:SendTmuxCommand(command) function! s:SendTmuxCommand(command)
let prefixed_command = "tmux " . a:command let prefixed_command = "tmux " . a:command
return system(prefixed_command) return s:Strip(system(prefixed_command))
endfunction endfunction
function! s:TargetedTmuxCommand(command, target_pane) function! s:TargetedTmuxCommand(command, target_pane)