|
|
|
@ -15,12 +15,12 @@ let g:VimuxRunnerType = get(g:, 'VimuxRunnerType', 'pane')
|
|
|
|
|
let g:VimuxTmuxCommand = get(g:, 'VimuxTmuxCommand', 'tmux')
|
|
|
|
|
let g:VimuxUseNearest = get(g:, 'VimuxUseNearest', v:true)
|
|
|
|
|
|
|
|
|
|
function! s:VimuxOption(name) abort
|
|
|
|
|
function! VimuxOption(name) abort
|
|
|
|
|
return get(b:, a:name, get(g:, a:name))
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
if !executable(s:VimuxOption('VimuxTmuxCommand'))
|
|
|
|
|
echohl ErrorMsg | echomsg 'Failed to find executable '.s:VimuxOption('VimuxTmuxCommand') | echohl None
|
|
|
|
|
if !executable(VimuxOption('VimuxTmuxCommand'))
|
|
|
|
|
echohl ErrorMsg | echomsg 'Failed to find executable '.VimuxOption('VimuxTmuxCommand') | echohl None
|
|
|
|
|
finish
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
@ -55,21 +55,17 @@ function! VimuxRunLastCommand()
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxRunCommand(command, ...)
|
|
|
|
|
if !exists('g:VimuxRunnerIndex') || s:VimuxHasRunner(g:VimuxRunnerIndex) ==# -1
|
|
|
|
|
if !exists('g:VimuxRunnerIndex') || s:hasRunner(g:VimuxRunnerIndex) ==# -1
|
|
|
|
|
call VimuxOpenRunner()
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
let l:autoreturn = 1
|
|
|
|
|
if exists('a:1')
|
|
|
|
|
let l:autoreturn = a:1
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
let resetSequence = s:VimuxOption('VimuxResetSequence')
|
|
|
|
|
let resetSequence = VimuxOption('VimuxResetSequence')
|
|
|
|
|
let g:VimuxLastCommand = a:command
|
|
|
|
|
|
|
|
|
|
call VimuxSendKeys(resetSequence)
|
|
|
|
|
call VimuxSendText(a:command)
|
|
|
|
|
|
|
|
|
|
if l:autoreturn ==# 1
|
|
|
|
|
call VimuxSendKeys('Enter')
|
|
|
|
|
endif
|
|
|
|
@ -81,76 +77,74 @@ endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxSendKeys(keys)
|
|
|
|
|
if exists('g:VimuxRunnerIndex')
|
|
|
|
|
call s:VimuxTmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys)
|
|
|
|
|
call VimuxTmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys)
|
|
|
|
|
else
|
|
|
|
|
echo 'No vimux runner pane/window. Create one with VimuxOpenRunner'
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxOpenRunner()
|
|
|
|
|
let nearestIndex = s:VimuxNearestIndex()
|
|
|
|
|
|
|
|
|
|
if s:VimuxOption('VimuxUseNearest') ==# 1 && nearestIndex != -1
|
|
|
|
|
let nearestIndex = s:nearestIndex()
|
|
|
|
|
if VimuxOption('VimuxUseNearest') ==# 1 && nearestIndex != -1
|
|
|
|
|
let g:VimuxRunnerIndex = nearestIndex
|
|
|
|
|
else
|
|
|
|
|
let extraArguments = s:VimuxOption('VimuxOpenExtraArgs')
|
|
|
|
|
if s:VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
let height = s:VimuxOption('VimuxHeight')
|
|
|
|
|
let orientation = s:VimuxOption('VimuxOrientation')
|
|
|
|
|
call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments)
|
|
|
|
|
elseif s:VimuxOption('VimuxRunnerType') ==# 'window'
|
|
|
|
|
call s:VimuxTmux('new-window '.extraArguments)
|
|
|
|
|
let extraArguments = VimuxOption('VimuxOpenExtraArgs')
|
|
|
|
|
if VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
let height = VimuxOption('VimuxHeight')
|
|
|
|
|
let orientation = VimuxOption('VimuxOrientation')
|
|
|
|
|
call VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments)
|
|
|
|
|
elseif VimuxOption('VimuxRunnerType') ==# 'window'
|
|
|
|
|
call VimuxTmux('new-window '.extraArguments)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
let g:VimuxRunnerIndex = s:VimuxTmuxIndex()
|
|
|
|
|
call s:VimuxSetRunnerName()
|
|
|
|
|
call s:VimuxTmux('last-'.s:VimuxOption('VimuxRunnerType'))
|
|
|
|
|
let g:VimuxRunnerIndex = s:tmuxIndex()
|
|
|
|
|
call s:setRunnerName()
|
|
|
|
|
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxCloseRunner()
|
|
|
|
|
if exists('g:VimuxRunnerIndex')
|
|
|
|
|
call s:VimuxTmux('kill-'.s:VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
|
|
|
|
|
call VimuxTmux('kill-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
|
|
|
|
|
unlet g:VimuxRunnerIndex
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxTogglePane()
|
|
|
|
|
if exists('g:VimuxRunnerIndex')
|
|
|
|
|
if s:VimuxOption('VimuxRunnerType') ==# 'window'
|
|
|
|
|
call s:VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.s:VimuxOption('VimuxHeight'))
|
|
|
|
|
let s:VimuxOption('VimuxRunnerType') = 'pane'
|
|
|
|
|
elseif s:VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '')
|
|
|
|
|
let s:VimuxOption('VimuxRunnerType') = 'window'
|
|
|
|
|
if VimuxOption('VimuxRunnerType') ==# 'window'
|
|
|
|
|
call VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('VimuxHeight'))
|
|
|
|
|
let VimuxOption('VimuxRunnerType') = 'pane'
|
|
|
|
|
elseif VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
let g:VimuxRunnerIndex=substitute(VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '')
|
|
|
|
|
let VimuxOption('VimuxRunnerType') = 'window'
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxZoomRunner()
|
|
|
|
|
if exists('g:VimuxRunnerIndex')
|
|
|
|
|
if s:VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
call s:VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
|
|
|
|
|
elseif s:VimuxOption('VimuxRunnerType') ==# 'window'
|
|
|
|
|
call s:VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
|
|
|
|
|
if VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
call VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
|
|
|
|
|
elseif VimuxOption('VimuxRunnerType') ==# 'window'
|
|
|
|
|
call VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxInspectRunner()
|
|
|
|
|
call s:VimuxTmux('select-'.s:VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
|
|
|
|
|
call s:VimuxTmux('copy-mode')
|
|
|
|
|
call VimuxTmux('select-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
|
|
|
|
|
call VimuxTmux('copy-mode')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxScrollUpInspect()
|
|
|
|
|
call VimuxInspectRunner()
|
|
|
|
|
call s:VimuxTmux('last-'.s:VimuxOption('VimuxRunnerType'))
|
|
|
|
|
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
|
|
|
|
|
call VimuxSendKeys('C-u')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxScrollDownInspect()
|
|
|
|
|
call VimuxInspectRunner()
|
|
|
|
|
call s:VimuxTmux('last-'.s:VimuxOption('VimuxRunnerType'))
|
|
|
|
|
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
|
|
|
|
|
call VimuxSendKeys('C-d')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
@ -166,63 +160,61 @@ endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxClearRunnerHistory()
|
|
|
|
|
if exists('g:VimuxRunnerIndex')
|
|
|
|
|
call s:VimuxTmux('clear-history -t '.g:VimuxRunnerIndex)
|
|
|
|
|
call VimuxTmux('clear-history -t '.g:VimuxRunnerIndex)
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! VimuxPromptCommand(...)
|
|
|
|
|
let command = a:0 ==# 1 ? a:1 : ''
|
|
|
|
|
let l:command = input(s:VimuxOption('VimuxPromptString'), command, 'shellcmd')
|
|
|
|
|
let l:command = input(VimuxOption('VimuxPromptString'), command, 'shellcmd')
|
|
|
|
|
call VimuxRunCommand(l:command)
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxTmux(arguments)
|
|
|
|
|
if s:VimuxOption('VimuxDebug')
|
|
|
|
|
echom s:VimuxOption('VimuxTmuxCommand').' '.a:arguments
|
|
|
|
|
function! VimuxTmux(arguments)
|
|
|
|
|
if VimuxOption('VimuxDebug')
|
|
|
|
|
echom VimuxOption('VimuxTmuxCommand').' '.a:arguments
|
|
|
|
|
endif
|
|
|
|
|
return system(s:VimuxOption('VimuxTmuxCommand').' '.a:arguments)
|
|
|
|
|
return system(VimuxOption('VimuxTmuxCommand').' '.a:arguments)
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxTmuxSession()
|
|
|
|
|
return s:VimuxTmuxProperty('#S')
|
|
|
|
|
function! s:tmuxSession()
|
|
|
|
|
return s:tmuxProperty('#S')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxTmuxIndex()
|
|
|
|
|
if s:VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
return s:VimuxTmuxPaneId()
|
|
|
|
|
function! s:tmuxIndex()
|
|
|
|
|
if VimuxOption('VimuxRunnerType') ==# 'pane'
|
|
|
|
|
return s:tmuxPaneId()
|
|
|
|
|
else
|
|
|
|
|
return s:VimuxTmuxWindowId()
|
|
|
|
|
return s:tmuxWindowId()
|
|
|
|
|
end
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxTmuxPaneId()
|
|
|
|
|
return s:VimuxTmuxProperty('#{pane_id}')
|
|
|
|
|
function! s:tmuxPaneId()
|
|
|
|
|
return s:tmuxProperty('#{pane_id}')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxTmuxWindowId()
|
|
|
|
|
return s:VimuxTmuxProperty('#{window_id}')
|
|
|
|
|
function! s:tmuxWindowId()
|
|
|
|
|
return s:tmuxProperty('#{window_id}')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxNearestIndex()
|
|
|
|
|
let t = s:VimuxOption('VimuxRunnerType')
|
|
|
|
|
let filter = s:VimuxGetTargetFilter()
|
|
|
|
|
let views = split(s:VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n')
|
|
|
|
|
|
|
|
|
|
function! s:nearestIndex()
|
|
|
|
|
let t = VimuxOption('VimuxRunnerType')
|
|
|
|
|
let filter = s:getTargetFilter()
|
|
|
|
|
let views = split(VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n')
|
|
|
|
|
for view in views
|
|
|
|
|
if match(view, '1:') ==# -1
|
|
|
|
|
return split(view, ':')[1]
|
|
|
|
|
endif
|
|
|
|
|
endfor
|
|
|
|
|
|
|
|
|
|
return -1
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxGetTargetFilter()
|
|
|
|
|
let targetName = s:VimuxOption('VimuxRunnerName')
|
|
|
|
|
function! s:getTargetFilter()
|
|
|
|
|
let targetName = VimuxOption('VimuxRunnerName')
|
|
|
|
|
if targetName ==# ''
|
|
|
|
|
return ''
|
|
|
|
|
endif
|
|
|
|
|
let t = s:VimuxOption('VimuxRunnerType')
|
|
|
|
|
let t = VimuxOption('VimuxRunnerType')
|
|
|
|
|
if t ==# 'window'
|
|
|
|
|
return " -f '#{==:#{window_name},".targetName."}'"
|
|
|
|
|
elseif t ==# 'pane'
|
|
|
|
@ -230,24 +222,24 @@ function! s:VimuxGetTargetFilter()
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxSetRunnerName()
|
|
|
|
|
let targetName = s:VimuxOption('VimuxRunnerName')
|
|
|
|
|
function! s:setRunnerName()
|
|
|
|
|
let targetName = VimuxOption('VimuxRunnerName')
|
|
|
|
|
if targetName ==# ''
|
|
|
|
|
return
|
|
|
|
|
return
|
|
|
|
|
endif
|
|
|
|
|
let t = s:VimuxOption('VimuxRunnerType')
|
|
|
|
|
let t = VimuxOption('VimuxRunnerType')
|
|
|
|
|
if t ==# 'window'
|
|
|
|
|
call s:VimuxTmux('rename-window '.targetName)
|
|
|
|
|
call VimuxTmux('rename-window '.targetName)
|
|
|
|
|
elseif t ==# 'pane'
|
|
|
|
|
call s:VimuxTmux('select-pane -T '.targetName)
|
|
|
|
|
call VimuxTmux('select-pane -T '.targetName)
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxTmuxProperty(property)
|
|
|
|
|
return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
|
|
|
|
|
function! s:tmuxProperty(property)
|
|
|
|
|
return substitute(VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:VimuxHasRunner(index)
|
|
|
|
|
let t = s:VimuxOption('VimuxRunnerType')
|
|
|
|
|
return match(s:VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index)
|
|
|
|
|
function! s:hasRunner(index)
|
|
|
|
|
let t = VimuxOption('VimuxRunnerType')
|
|
|
|
|
return match(VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index)
|
|
|
|
|
endfunction
|
|
|
|
|