Skip to content

Commit

Permalink
Merge pull request #3427 from lifecrisis/sh-buffer-vars
Browse files Browse the repository at this point in the history
Check for Vim's shell type buffer variables before falling back to the file type
  • Loading branch information
hsanson authored Nov 4, 2020
2 parents 557a1ed + 31b7a2d commit 1ec573b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
22 changes: 16 additions & 6 deletions autoload/ale/handlers/sh.vim
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
" Author: w0rp <[email protected]>

" Get the shell type for a buffer, based on the hashbang line.
function! ale#handlers#sh#GetShellType(buffer) abort
let l:bang_line = get(getbufline(a:buffer, 1), 0, '')
let l:shebang = 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# '#!'
" Take the shell executable from the shebang, if we can.
if l:shebang[:1] is# '#!'
" Remove options like -e, etc.
let l:command = substitute(l:bang_line, ' --\?[a-zA-Z0-9]\+', '', 'g')
let l:command = substitute(l:shebang, ' --\?[a-zA-Z0-9]\+', '', 'g')
endif

" If we couldn't find a hashbang, try the filetype
" With no shebang line, attempt to use Vim's buffer-local variables.
if l:command is# ''
if getbufvar(a:buffer, 'is_bash', 0)
let l:command = 'bash'
elseif getbufvar(a:buffer, 'is_sh', 0)
let l:command = 'sh'
elseif getbufvar(a:buffer, 'is_kornshell', 0)
let l:command = 'ksh'
endif
endif

" If we couldn't find a shebang, try the filetype
if l:command is# ''
let l:command = &filetype
endif
Expand Down
9 changes: 0 additions & 9 deletions autoload/ale/handlers/shellcheck.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ function! ale#handlers#shellcheck#GetDialectArgument(buffer) abort
return l:shell_type
endif

" If there's no hashbang, try using Vim's buffer variables.
if getbufvar(a:buffer, 'is_bash', 0)
return 'bash'
elseif getbufvar(a:buffer, 'is_sh', 0)
return 'sh'
elseif getbufvar(a:buffer, 'is_kornshell', 0)
return 'ksh'
endif

return ''
endfunction

Expand Down

0 comments on commit 1ec573b

Please sign in to comment.