fix a small bug with the sh syntax checker and refactor
Previously, if we edited a new bash script then we would have to wipeout the buffer and recreate it to get syntastic to recognise it as a bash script. This is because it parsed out a magic number and cached that - and it trivially fails to find a magic number when you create a new file. So recheck for a magic number if it is currently empty. Also, do a small refactor.
This commit is contained in:
parent
ea7d9779f0
commit
ae9f45cf4a
@ -14,28 +14,29 @@ if exists('loaded_sh_syntax_checker')
|
||||
endif
|
||||
let loaded_sh_syntax_checker = 1
|
||||
|
||||
function! GetShell()
|
||||
let shebang = getbufline(bufnr('%'), 1)[0]
|
||||
if len(shebang) > 0
|
||||
if match(shebang, 'bash') >= 0
|
||||
return 'bash'
|
||||
elseif match(shebang, 'zsh') >= 0
|
||||
return 'zsh'
|
||||
elseif match(shebang, 'sh') >= 0
|
||||
return 'sh'
|
||||
function! s:GetShell()
|
||||
if !exists('b:shell') || b:shell == ""
|
||||
let shebang = getbufline(bufnr('%'), 1)[0]
|
||||
if len(shebang) > 0
|
||||
if match(shebang, 'bash') >= 0
|
||||
let b:shell = 'bash'
|
||||
elseif match(shebang, 'zsh') >= 0
|
||||
let b:shell = 'zsh'
|
||||
elseif match(shebang, 'sh') >= 0
|
||||
let b:shell = 'sh'
|
||||
else
|
||||
let b:shell = ''
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return ''
|
||||
return b:shell
|
||||
endfunction
|
||||
|
||||
function! SyntaxCheckers_sh_GetLocList()
|
||||
if !exists('b:shell')
|
||||
let b:shell = GetShell()
|
||||
endif
|
||||
if len(b:shell) == 0 || !executable(b:shell)
|
||||
if len(s:GetShell()) == 0 || !executable(s:GetShell())
|
||||
return []
|
||||
endif
|
||||
let output = split(system(b:shell.' -n '.shellescape(expand('%'))), '\n')
|
||||
let output = split(system(s:GetShell().' -n '.shellescape(expand('%'))), '\n')
|
||||
if v:shell_error != 0
|
||||
let result = []
|
||||
for err_line in output
|
||||
|
Loading…
Reference in New Issue
Block a user