Fix vimscript lint errors and add CI linter (#181)

* Add Vint config file for vimscript linting
* Replace underscore convention with proper script-local scopes
* Prefer single quoted strings
* Use the full option name
* Use robust operators
fix-tmux-next-3dot4
Caleb Maclennan 3 years ago committed by GitHub
commit bde8b4cb37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
cmdargs:
severity: style_problem
color: true
env:
neovim: false

@ -1,9 +1,9 @@
if exists("g:loaded_vimux") || &cp if exists('g:loaded_vimux') || &compatible
finish finish
endif endif
let g:loaded_vimux = 1 let g:loaded_vimux = 1
function! _VimuxOption(option, default) function! s:VimuxOption(option, default)
if exists(a:option) if exists(a:option)
return eval(a:option) return eval(a:option)
else else
@ -11,12 +11,12 @@ function! _VimuxOption(option, default)
endif endif
endfunction endfunction
function! _VimuxTmuxCmd() function! s:VimuxTmuxCmd()
return _VimuxOption("g:VimuxTmuxCommand", "tmux") return s:VimuxOption('g:VimuxTmuxCommand', 'tmux')
endfunction endfunction
if !executable(_VimuxTmuxCmd()) if !executable(s:VimuxTmuxCmd())
echohl ErrorMsg | echomsg "Failed to find executable "._VimuxTmuxCmd() | echohl None echohl ErrorMsg | echomsg 'Failed to find executable '.s:VimuxTmuxCmd() | echohl None
finish finish
endif endif
@ -35,220 +35,220 @@ command VimuxClearRunnerHistory :call VimuxClearRunnerHistory()
command VimuxTogglePane :call VimuxTogglePane() command VimuxTogglePane :call VimuxTogglePane()
function! VimuxRunCommandInDir(command, useFile) function! VimuxRunCommandInDir(command, useFile)
let l:file = "" let l:file = ''
if a:useFile ==# 1 if a:useFile ==# 1
let l:file = shellescape(expand('%:t'), 1) let l:file = shellescape(expand('%:t'), 1)
endif endif
call VimuxRunCommand("(cd ".shellescape(expand('%:p:h'), 1)." && ".a:command." ".l:file.")") call VimuxRunCommand('(cd '.shellescape(expand('%:p:h'), 1).' && '.a:command.' '.l:file.')')
endfunction endfunction
function! VimuxRunLastCommand() function! VimuxRunLastCommand()
if exists("g:VimuxRunnerIndex") if exists('g:VimuxRunnerIndex')
call VimuxRunCommand(g:VimuxLastCommand) call VimuxRunCommand(g:VimuxLastCommand)
else else
echo "No last vimux command." echo 'No last vimux command.'
endif endif
endfunction endfunction
function! VimuxRunCommand(command, ...) function! VimuxRunCommand(command, ...)
if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1 if !exists('g:VimuxRunnerIndex') || s:VimuxHasRunner(g:VimuxRunnerIndex) ==# -1
call VimuxOpenRunner() call VimuxOpenRunner()
endif endif
let l:autoreturn = 1 let l:autoreturn = 1
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 = s:VimuxOption('g:VimuxResetSequence', 'q C-u')
let g:VimuxLastCommand = a:command let g:VimuxLastCommand = a:command
call VimuxSendKeys(resetSequence) call VimuxSendKeys(resetSequence)
call VimuxSendText(a:command) call VimuxSendText(a:command)
if l:autoreturn == 1 if l:autoreturn ==# 1
call VimuxSendKeys("Enter") call VimuxSendKeys('Enter')
endif endif
endfunction endfunction
function! VimuxSendText(text) function! VimuxSendText(text)
call VimuxSendKeys(shellescape(substitute(a:text, "\n$", " ", ""))) call VimuxSendKeys(shellescape(substitute(a:text, '\n$', ' ', '')))
endfunction endfunction
function! VimuxSendKeys(keys) function! VimuxSendKeys(keys)
if exists("g:VimuxRunnerIndex") if exists('g:VimuxRunnerIndex')
call _VimuxTmux("send-keys -t ".g:VimuxRunnerIndex." ".a:keys) call s:VimuxTmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys)
else else
echo "No vimux runner pane/window. Create one with VimuxOpenRunner" echo 'No vimux runner pane/window. Create one with VimuxOpenRunner'
endif endif
endfunction endfunction
function! VimuxOpenRunner() function! VimuxOpenRunner()
let nearestIndex = _VimuxNearestIndex() let nearestIndex = s:VimuxNearestIndex()
if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1 if s:VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1
let g:VimuxRunnerIndex = nearestIndex let g:VimuxRunnerIndex = nearestIndex
else else
let extraArguments = _VimuxOption("g:VimuxOpenExtraArgs", "") let extraArguments = s:VimuxOption('g:VimuxOpenExtraArgs', '')
if _VimuxRunnerType() == "pane" if s:VimuxRunnerType() ==# 'pane'
let height = _VimuxOption("g:VimuxHeight", 20) let height = s:VimuxOption('g:VimuxHeight', 20)
let orientation = _VimuxOption("g:VimuxOrientation", "v") let orientation = s:VimuxOption('g:VimuxOrientation', 'v')
call _VimuxTmux("split-window -p ".height." -".orientation." ".extraArguments) call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments)
elseif _VimuxRunnerType() == "window" elseif s:VimuxRunnerType() ==# 'window'
call _VimuxTmux("new-window ".extraArguments) call s:VimuxTmux('new-window '.extraArguments)
endif endif
let g:VimuxRunnerIndex = _VimuxTmuxIndex() let g:VimuxRunnerIndex = s:VimuxTmuxIndex()
call _VimuxSetRunnerName() call s:VimuxSetRunnerName()
call _VimuxTmux("last-"._VimuxRunnerType()) call s:VimuxTmux('last-'.s:VimuxRunnerType())
endif endif
endfunction endfunction
function! VimuxCloseRunner() function! VimuxCloseRunner()
if exists("g:VimuxRunnerIndex") if exists('g:VimuxRunnerIndex')
call _VimuxTmux("kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) call s:VimuxTmux('kill-'.s: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 _VimuxRunnerType() == "window" if s:VimuxRunnerType() ==# 'window'
call _VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p "._VimuxOption("g:VimuxHeight", 20)) call s:VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.s:VimuxOption('g:VimuxHeight', 20))
let g:VimuxRunnerType = "pane" let g:VimuxRunnerType = 'pane'
elseif _VimuxRunnerType() == "pane" elseif s:VimuxRunnerType() ==# 'pane'
let g:VimuxRunnerIndex=substitute(_VimuxTmux("break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_id}'"), "\n", "", "") let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '')
let g:VimuxRunnerType = "window" let g:VimuxRunnerType = 'window'
endif endif
endif endif
endfunction endfunction
function! VimuxZoomRunner() function! VimuxZoomRunner()
if exists("g:VimuxRunnerIndex") if exists('g:VimuxRunnerIndex')
if _VimuxRunnerType() == "pane" if s:VimuxRunnerType() ==# 'pane'
call _VimuxTmux("resize-pane -Z -t ".g:VimuxRunnerIndex) call s:VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
elseif _VimuxRunnerType() == "window" elseif s:VimuxRunnerType() ==# 'window'
call _VimuxTmux("select-window -t ".g:VimuxRunnerIndex) call s:VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
endif endif
endif endif
endfunction endfunction
function! VimuxInspectRunner() function! VimuxInspectRunner()
call _VimuxTmux("select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) call s:VimuxTmux('select-'.s:VimuxRunnerType().' -t '.g:VimuxRunnerIndex)
call _VimuxTmux("copy-mode") call s:VimuxTmux('copy-mode')
endfunction endfunction
function! VimuxScrollUpInspect() function! VimuxScrollUpInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call _VimuxTmux("last-"._VimuxRunnerType()) call s:VimuxTmux('last-'.s:VimuxRunnerType())
call VimuxSendKeys("C-u") call VimuxSendKeys('C-u')
endfunction endfunction
function! VimuxScrollDownInspect() function! VimuxScrollDownInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call _VimuxTmux("last-"._VimuxRunnerType()) call s:VimuxTmux('last-'.s:VimuxRunnerType())
call VimuxSendKeys("C-d") call VimuxSendKeys('C-d')
endfunction endfunction
function! VimuxInterruptRunner() function! VimuxInterruptRunner()
call VimuxSendKeys("^c") call VimuxSendKeys('^c')
endfunction endfunction
function! VimuxClearTerminalScreen() function! VimuxClearTerminalScreen()
if exists("g:VimuxRunnerIndex") if exists('g:VimuxRunnerIndex')
call VimuxSendKeys("C-l") call VimuxSendKeys('C-l')
endif endif
endfunction endfunction
function! VimuxClearRunnerHistory() function! VimuxClearRunnerHistory()
if exists("g:VimuxRunnerIndex") if exists('g:VimuxRunnerIndex')
call _VimuxTmux("clear-history -t ".g:VimuxRunnerIndex) call s:VimuxTmux('clear-history -t '.g:VimuxRunnerIndex)
endif endif
endfunction 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(s:VimuxOption('g:VimuxPromptString', 'Command? '), command, 'shellcmd')
call VimuxRunCommand(l:command) call VimuxRunCommand(l:command)
endfunction endfunction
function! _VimuxTmux(arguments) function! s:VimuxTmux(arguments)
if _VimuxOption("g:VimuxDebug", 0) != 0 if s:VimuxOption('g:VimuxDebug', 0) != 0
echom _VimuxTmuxCmd()." ".a:arguments echom s:VimuxTmuxCmd().' '.a:arguments
endif endif
return system(_VimuxTmuxCmd()." ".a:arguments) return system(s:VimuxTmuxCmd().' '.a:arguments)
endfunction endfunction
function! _VimuxTmuxSession() function! s:VimuxTmuxSession()
return _VimuxTmuxProperty("#S") return s:VimuxTmuxProperty('#S')
endfunction endfunction
function! _VimuxTmuxIndex() function! s:VimuxTmuxIndex()
if _VimuxRunnerType() == "pane" if s:VimuxRunnerType() ==# 'pane'
return _VimuxTmuxPaneId() return s:VimuxTmuxPaneId()
else else
return _VimuxTmuxWindowId() return s:VimuxTmuxWindowId()
end end
endfunction endfunction
function! _VimuxTmuxPaneId() function! s:VimuxTmuxPaneId()
return _VimuxTmuxProperty("#{pane_id}") return s:VimuxTmuxProperty('#{pane_id}')
endfunction endfunction
function! _VimuxTmuxWindowId() function! s:VimuxTmuxWindowId()
return _VimuxTmuxProperty("#{window_id}") return s:VimuxTmuxProperty('#{window_id}')
endfunction endfunction
function! _VimuxNearestIndex() function! s:VimuxNearestIndex()
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
let filter = _VimuxGetTargetFilter() let filter = s:VimuxGetTargetFilter()
let views = split(_VimuxTmux("list-".t."s -F '#{".t."_active}:#{".t."_id}'".filter), "\n") let views = split(s:VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n')
for view in views for view in views
if match(view, "1:") == -1 if match(view, '1:') ==# -1
return split(view, ":")[1] return split(view, ':')[1]
endif endif
endfor endfor
return -1 return -1
endfunction endfunction
function! _VimuxGetTargetFilter() function! s:VimuxGetTargetFilter()
let targetName = _VimuxOption("g:VimuxRunnerName", "") let targetName = s:VimuxOption('g:VimuxRunnerName', '')
if targetName == "" if targetName ==# ''
return "" return ''
endif endif
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
if t == "window" if t ==# 'window'
return " -f '#{==:#{window_name},".targetName."}'" return " -f '#{==:#{window_name},".targetName."}'"
elseif t == "pane" elseif t ==# 'pane'
return " -f '#{==:#{pane_title},".targetName."}'" return " -f '#{==:#{pane_title},".targetName."}'"
endif endif
endfunction endfunction
function! _VimuxSetRunnerName() function! s:VimuxSetRunnerName()
let targetName = _VimuxOption("g:VimuxRunnerName", "") let targetName = s:VimuxOption('g:VimuxRunnerName', '')
if targetName == "" if targetName ==# ''
return return
endif endif
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
if t == "window" if t ==# 'window'
call _VimuxTmux("rename-window ".targetName) call s:VimuxTmux('rename-window '.targetName)
elseif t == "pane" elseif t ==# 'pane'
call _VimuxTmux("select-pane -T ".targetName) call s:VimuxTmux('select-pane -T '.targetName)
endif endif
endfunction endfunction
function! _VimuxRunnerType() function! s:VimuxRunnerType()
return _VimuxOption("g:VimuxRunnerType", "pane") return s:VimuxOption('g:VimuxRunnerType', 'pane')
endfunction endfunction
function! _VimuxTmuxProperty(property) function! s:VimuxTmuxProperty(property)
return substitute(_VimuxTmux("display -p '".a:property."'"), '\n$', '', '') return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
endfunction endfunction
function! _VimuxHasRunner(index) function! s:VimuxHasRunner(index)
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
return match(_VimuxTmux("list-".t."s -F '#{".t."_id}'"), a:index) return match(s:VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index)
endfunction endfunction

Loading…
Cancel
Save