Prevent kill wrong background window

Closes #37 - Check for detached window title before killing
This commit is contained in:
Chris Toomey 2015-02-07 00:14:53 -05:00
parent 0a80e5bc67
commit 515f7d8730

View File

@ -53,12 +53,29 @@ function! s:ValidRunnerPaneSet()
return 1 return 1
endfunction endfunction
function! s:DetachedPaneAvailable() function! s:DetachedWindowOutOfSync()
if !exists("s:detached_window") let window_map = s:WindowMap()
call s:EchoError("No detached runner pane.") if index(keys(window_map), s:detached_window) == -1
return 0
endif
return 1 return 1
endif
if s:WindowMap()[s:detached_window] != g:VtrDetachedName
return 1
endif
return 0
endfunction
function! s:DetachedPaneAvailable()
if exists("s:detached_window")
if s:DetachedWindowOutOfSync()
call s:EchoError("Detached pane out of sync. Unable to kill")
unlet s:detached_window
return 0
endif
else
call s:EchoError("No detached runner pane.")
return 0
endif
return 1
endfunction endfunction
function! s:RequireLocalPaneOrDetached() function! s:RequireLocalPaneOrDetached()
@ -77,7 +94,18 @@ function! s:KillLocalRunner()
endif endif
endfunction endfunction
function! s:WindowMap()
let window_pattern = '\v(\d+): ([-_a-zA-Z]{-})[-\* ]\s.*'
let window_map = {}
for line in split(s:SendTmuxCommand("list-windows"), "\n")
let dem = split(substitute(line, window_pattern, '\1:\2', ""), ':')
let window_map[dem[0]] = dem[1]
endfor
return window_map
endfunction
function! s:KillDetachedWindow() function! s:KillDetachedWindow()
if !s:DetachedPaneAvailable() | return | endif
let cmd = join(["kill-window", '-t', s:detached_window]) let cmd = join(["kill-window", '-t', s:detached_window])
call s:SendTmuxCommand(cmd) call s:SendTmuxCommand(cmd)
unlet s:detached_window unlet s:detached_window