summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2020-08-17 21:29:16 +0100
committerGitHub <noreply@github.com>2020-08-17 21:29:16 +0100
commiteb864730e2bf843f83dcf58ae43c802ad0cad8ee (patch)
tree2fb99823bad74b288ce3f5868a871490c0d4cb3b /autoload
parent514e5a8baa539f38c62881673727be6f67935d75 (diff)
parentece229c06f36efdc172ae6d70c73b72a16bb4cdf (diff)
downloadale-eb864730e2bf843f83dcf58ae43c802ad0cad8ee.zip
Merge pull request #2906 from elebow/shelldetect-fall-back-to-filetype-if-no-hashbang
ShellDetect falls back to filetype if no hashbang (fixes #2886)
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/handlers/sh.vim17
1 files changed, 12 insertions, 5 deletions
diff --git a/autoload/ale/handlers/sh.vim b/autoload/ale/handlers/sh.vim
index 75eaf71f..1e50cb89 100644
--- a/autoload/ale/handlers/sh.vim
+++ b/autoload/ale/handlers/sh.vim
@@ -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')
+ 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
+ " 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