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
|
endif
|
||||||
let loaded_sh_syntax_checker = 1
|
let loaded_sh_syntax_checker = 1
|
||||||
|
|
||||||
function! GetShell()
|
function! s:GetShell()
|
||||||
let shebang = getbufline(bufnr('%'), 1)[0]
|
if !exists('b:shell') || b:shell == ""
|
||||||
if len(shebang) > 0
|
let shebang = getbufline(bufnr('%'), 1)[0]
|
||||||
if match(shebang, 'bash') >= 0
|
if len(shebang) > 0
|
||||||
return 'bash'
|
if match(shebang, 'bash') >= 0
|
||||||
elseif match(shebang, 'zsh') >= 0
|
let b:shell = 'bash'
|
||||||
return 'zsh'
|
elseif match(shebang, 'zsh') >= 0
|
||||||
elseif match(shebang, 'sh') >= 0
|
let b:shell = 'zsh'
|
||||||
return 'sh'
|
elseif match(shebang, 'sh') >= 0
|
||||||
|
let b:shell = 'sh'
|
||||||
|
else
|
||||||
|
let b:shell = ''
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
return ''
|
return b:shell
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SyntaxCheckers_sh_GetLocList()
|
function! SyntaxCheckers_sh_GetLocList()
|
||||||
if !exists('b:shell')
|
if len(s:GetShell()) == 0 || !executable(s:GetShell())
|
||||||
let b:shell = GetShell()
|
|
||||||
endif
|
|
||||||
if len(b:shell) == 0 || !executable(b:shell)
|
|
||||||
return []
|
return []
|
||||||
endif
|
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
|
if v:shell_error != 0
|
||||||
let result = []
|
let result = []
|
||||||
for err_line in output
|
for err_line in output
|
||||||
|
Loading…
Reference in New Issue
Block a user