Merge pull request #183 from mvanderkamp/initialize_settings

fix-tmux-next-3dot4
Caleb Maclennan 3 years ago committed by GitHub
commit 8cc4fe9678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -287,7 +287,9 @@ extra return. Thanks to @trptcolin for discovering this issue.
============================================================================== ==============================================================================
CONFIGURATION (4) *VimuxConfiguration* CONFIGURATION (4) *VimuxConfiguration*
You can configure Vimux like this: You can configure Vimux as follows. Note that all occurances of global
variables `g:Vimux...` may also be set using buffer variables `b:Vimux...` to
change the behavior of Vimux in just the current buffer.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*VimuxConfiguration_height* *VimuxConfiguration_height*

@ -3,20 +3,24 @@ if exists('g:loaded_vimux') || &compatible
endif endif
let g:loaded_vimux = 1 let g:loaded_vimux = 1
function! VimuxOption(option, default) " Set up all global options with defaults right away, in one place
if exists(a:option) let g:VimuxDebug = get(g:, 'VimuxDebug', v:false)
return eval(a:option) let g:VimuxHeight = get(g:, 'VimuxHeight', 20)
else let g:VimuxOpenExtraArgs = get(g:, 'VimuxOpenExtraArgs', '')
return a:default let g:VimuxOrientation = get(g:, 'VimuxOrientation', 'v')
endif let g:VimuxPromptString = get(g:, 'VimuxPromptString', 'Command? ')
endfunction let g:VimuxResetSequence = get(g:, 'VimuxResetSequence', 'q C-u')
let g:VimuxRunnerName = get(g:, 'VimuxRunnerName', '')
function! s:tmuxCmd() let g:VimuxRunnerType = get(g:, 'VimuxRunnerType', 'pane')
return VimuxOption('g:VimuxTmuxCommand', 'tmux') let g:VimuxTmuxCommand = get(g:, 'VimuxTmuxCommand', 'tmux')
endfunction let g:VimuxUseNearest = get(g:, 'VimuxUseNearest', v:true)
if !executable(s:tmuxCmd()) function! VimuxOption(name) abort
echohl ErrorMsg | echomsg 'Failed to find executable '.s:tmuxCmd() | echohl None return get(b:, a:name, get(g:, a:name))
endfunction
if !executable(VimuxOption('VimuxTmuxCommand'))
echohl ErrorMsg | echomsg 'Failed to find executable '.VimuxOption('VimuxTmuxCommand') | echohl None
finish finish
endif endif
@ -58,7 +62,7 @@ function! VimuxRunCommand(command, ...)
if exists('a:1') if exists('a:1')
let l:autoreturn = a:1 let l:autoreturn = a:1
endif endif
let resetSequence = VimuxOption('g:VimuxResetSequence', 'q C-u') let resetSequence = VimuxOption('VimuxResetSequence')
let g:VimuxLastCommand = a:command let g:VimuxLastCommand = a:command
call VimuxSendKeys(resetSequence) call VimuxSendKeys(resetSequence)
call VimuxSendText(a:command) call VimuxSendText(a:command)
@ -81,66 +85,66 @@ endfunction
function! VimuxOpenRunner() function! VimuxOpenRunner()
let nearestIndex = s:nearestIndex() let nearestIndex = s:nearestIndex()
if VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1 if VimuxOption('VimuxUseNearest') ==# 1 && nearestIndex != -1
let g:VimuxRunnerIndex = nearestIndex let g:VimuxRunnerIndex = nearestIndex
else else
let extraArguments = VimuxOption('g:VimuxOpenExtraArgs', '') let extraArguments = VimuxOption('VimuxOpenExtraArgs')
if s:runnerType() ==# 'pane' if VimuxOption('VimuxRunnerType') ==# 'pane'
let height = VimuxOption('g:VimuxHeight', 20) let height = VimuxOption('VimuxHeight')
let orientation = VimuxOption('g:VimuxOrientation', 'v') let orientation = VimuxOption('VimuxOrientation')
call VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments) call VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments)
elseif s:runnerType() ==# 'window' elseif VimuxOption('VimuxRunnerType') ==# 'window'
call VimuxTmux('new-window '.extraArguments) call VimuxTmux('new-window '.extraArguments)
endif endif
let g:VimuxRunnerIndex = s:tmuxIndex() let g:VimuxRunnerIndex = s:tmuxIndex()
call s:setRunnerName() call s:setRunnerName()
call VimuxTmux('last-'.s:runnerType()) call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
endif endif
endfunction endfunction
function! VimuxCloseRunner() function! VimuxCloseRunner()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
call VimuxTmux('kill-'.s:runnerType().' -t '.g:VimuxRunnerIndex) call VimuxTmux('kill-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
unlet g:VimuxRunnerIndex unlet g:VimuxRunnerIndex
endif endif
endfunction endfunction
function! VimuxTogglePane() function! VimuxTogglePane()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
if s:runnerType() ==# 'window' if VimuxOption('VimuxRunnerType') ==# 'window'
call VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('g:VimuxHeight', 20)) call VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('VimuxHeight'))
let g:VimuxRunnerType = 'pane' let VimuxOption('VimuxRunnerType') = 'pane'
elseif s:runnerType() ==# 'pane' elseif VimuxOption('VimuxRunnerType') ==# 'pane'
let g:VimuxRunnerIndex=substitute(VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '') let g:VimuxRunnerIndex=substitute(VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '')
let g:VimuxRunnerType = 'window' let VimuxOption('VimuxRunnerType') = 'window'
endif endif
endif endif
endfunction endfunction
function! VimuxZoomRunner() function! VimuxZoomRunner()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
if s:runnerType() ==# 'pane' if VimuxOption('VimuxRunnerType') ==# 'pane'
call VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex) call VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
elseif s:runnerType() ==# 'window' elseif VimuxOption('VimuxRunnerType') ==# 'window'
call VimuxTmux('select-window -t '.g:VimuxRunnerIndex) call VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
endif endif
endif endif
endfunction endfunction
function! VimuxInspectRunner() function! VimuxInspectRunner()
call VimuxTmux('select-'.s:runnerType().' -t '.g:VimuxRunnerIndex) call VimuxTmux('select-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
call VimuxTmux('copy-mode') call VimuxTmux('copy-mode')
endfunction endfunction
function! VimuxScrollUpInspect() function! VimuxScrollUpInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call VimuxTmux('last-'.s:runnerType()) call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
call VimuxSendKeys('C-u') call VimuxSendKeys('C-u')
endfunction endfunction
function! VimuxScrollDownInspect() function! VimuxScrollDownInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call VimuxTmux('last-'.s:runnerType()) call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
call VimuxSendKeys('C-d') call VimuxSendKeys('C-d')
endfunction endfunction
@ -162,15 +166,15 @@ endfunction
function! VimuxPromptCommand(...) function! VimuxPromptCommand(...)
let command = a:0 ==# 1 ? a:1 : '' let command = a:0 ==# 1 ? a:1 : ''
let l:command = input(VimuxOption('g:VimuxPromptString', 'Command? '), command, 'shellcmd') let l:command = input(VimuxOption('VimuxPromptString'), command, 'shellcmd')
call VimuxRunCommand(l:command) call VimuxRunCommand(l:command)
endfunction endfunction
function! VimuxTmux(arguments) function! VimuxTmux(arguments)
if VimuxOption('g:VimuxDebug', 0) != 0 if VimuxOption('VimuxDebug')
echom s:tmuxCmd().' '.a:arguments echom VimuxOption('VimuxTmuxCommand').' '.a:arguments
endif endif
return system(s:tmuxCmd().' '.a:arguments) return system(VimuxOption('VimuxTmuxCommand').' '.a:arguments)
endfunction endfunction
function! s:tmuxSession() function! s:tmuxSession()
@ -178,7 +182,7 @@ function! s:tmuxSession()
endfunction endfunction
function! s:tmuxIndex() function! s:tmuxIndex()
if s:runnerType() ==# 'pane' if VimuxOption('VimuxRunnerType') ==# 'pane'
return s:tmuxPaneId() return s:tmuxPaneId()
else else
return s:tmuxWindowId() return s:tmuxWindowId()
@ -194,7 +198,7 @@ function! s:tmuxWindowId()
endfunction endfunction
function! s:nearestIndex() function! s:nearestIndex()
let t = s:runnerType() let t = VimuxOption('VimuxRunnerType')
let filter = s:getTargetFilter() let filter = s:getTargetFilter()
let views = split(VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n') let views = split(VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n')
for view in views for view in views
@ -206,11 +210,11 @@ function! s:nearestIndex()
endfunction endfunction
function! s:getTargetFilter() function! s:getTargetFilter()
let targetName = VimuxOption('g:VimuxRunnerName', '') let targetName = VimuxOption('VimuxRunnerName')
if targetName ==# '' if targetName ==# ''
return '' return ''
endif endif
let t = s:runnerType() let t = VimuxOption('VimuxRunnerType')
if t ==# 'window' if t ==# 'window'
return " -f '#{==:#{window_name},".targetName."}'" return " -f '#{==:#{window_name},".targetName."}'"
elseif t ==# 'pane' elseif t ==# 'pane'
@ -219,11 +223,11 @@ function! s:getTargetFilter()
endfunction endfunction
function! s:setRunnerName() function! s:setRunnerName()
let targetName = VimuxOption('g:VimuxRunnerName', '') let targetName = VimuxOption('VimuxRunnerName')
if targetName ==# '' if targetName ==# ''
return return
endif endif
let t = s:runnerType() let t = VimuxOption('VimuxRunnerType')
if t ==# 'window' if t ==# 'window'
call VimuxTmux('rename-window '.targetName) call VimuxTmux('rename-window '.targetName)
elseif t ==# 'pane' elseif t ==# 'pane'
@ -231,15 +235,11 @@ function! s:setRunnerName()
endif endif
endfunction endfunction
function! s:runnerType()
return VimuxOption('g:VimuxRunnerType', 'pane')
endfunction
function! s:tmuxProperty(property) function! s:tmuxProperty(property)
return substitute(VimuxTmux("display -p '".a:property."'"), '\n$', '', '') return substitute(VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
endfunction endfunction
function! s:hasRunner(index) function! s:hasRunner(index)
let t = s:runnerType() let t = VimuxOption('VimuxRunnerType')
return match(VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index) return match(VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index)
endfunction endfunction

Loading…
Cancel
Save