Merge pull request #2906 from elebow/shelldetect-fall-back-to-filetype-if-no-hashbang

ShellDetect falls back to filetype if no hashbang (fixes #2886)
This commit is contained in:
w0rp
2020-08-17 21:29:16 +01:00
committed by GitHub
3 changed files with 24 additions and 7 deletions

View File

@@ -4,17 +4,24 @@
function! ale#handlers#sh#GetShellType(buffer) abort
let l:bang_line = get(getbufline(a:buffer, 1), 0, '')
let l:command = ''
" Take the shell executable from the hashbang, if we can.
if l:bang_line[:1] is# '#!'
" Remove options like -e, etc.
let l:command = substitute(l:bang_line, ' --\?[a-zA-Z0-9]\+', '', 'g')
for l:possible_shell in ['bash', 'dash', 'ash', 'tcsh', 'csh', 'zsh', 'ksh', 'sh']
if l:command =~# l:possible_shell . '\s*$'
return l:possible_shell
endif
endfor
endif
" If we couldn't find a hashbang, try the filetype
if l:command is# ''
let l:command = &filetype
endif
for l:possible_shell in ['bash', 'dash', 'ash', 'tcsh', 'csh', 'zsh', 'ksh', 'sh']
if l:command =~# l:possible_shell . '\s*$'
return l:possible_shell
endif
endfor
return ''
endfunction