Merge branch 'shell-detection'
This commit is contained in:
commit
a1ecf9ecea
2 changed files with 28 additions and 9 deletions
|
@ -10,24 +10,29 @@ let g:loaded_ale_linters_sh_shell = 1
|
|||
" This option can be changed to change the default shell when the shell
|
||||
" cannot be taken from the hashbang line.
|
||||
if !exists('g:ale_linters_sh_shell_default_shell')
|
||||
let g:ale_linters_sh_shell_default_shell = 'bash'
|
||||
let g:ale_linters_sh_shell_default_shell = fnamemodify($SHELL, ':t')
|
||||
|
||||
if g:ale_linters_sh_shell_default_shell ==# ''
|
||||
let g:ale_linters_sh_shell_default_shell = 'bash'
|
||||
endif
|
||||
endif
|
||||
|
||||
function! ale_linters#sh#shell#GetExecutable(buffer)
|
||||
let shell = g:ale_linters_sh_shell_default_shell
|
||||
|
||||
let banglines = getbufline(a:buffer, 1)
|
||||
|
||||
" Take the shell executable from the hashbang, if we can.
|
||||
if len(banglines) == 1
|
||||
let bangmatch = matchlist(banglines[0], '^#!\([^ ]\+\)')
|
||||
if len(banglines) == 1 && banglines[0] =~# '^#!'
|
||||
" Remove options like -e, etc.
|
||||
let line = substitute(banglines[0], '--\?[a-zA-Z0-9]\+', '', 'g')
|
||||
|
||||
if len(bangmatch) > 0
|
||||
let shell = bangmatch[1]
|
||||
endif
|
||||
for possible_shell in ['bash', 'tcsh', 'csh', 'zsh', 'sh']
|
||||
if line =~# possible_shell . '\s*$'
|
||||
return possible_shell
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
return shell
|
||||
return g:ale_linters_sh_shell_default_shell
|
||||
endfunction
|
||||
|
||||
function! ale_linters#sh#shell#GetCommand(buffer)
|
||||
|
|
14
doc/ale.txt
14
doc/ale.txt
|
@ -14,6 +14,7 @@ CONTENTS *ale-contents*
|
|||
4.2. phpcs......................................|ale-linter-options-phpcs|
|
||||
4.3. c-gcc......................................|ale-linter-options-c-gcc|
|
||||
4.4. cpp-gcc....................................|ale-linter-options-cpp-gcc|
|
||||
4.5. shell......................................|ale-linter-options-shell|
|
||||
5. API............................................|ale-api|
|
||||
6. Contact........................................|ale-contact|
|
||||
|
||||
|
@ -287,6 +288,19 @@ Default: `'-Wall'`
|
|||
|
||||
This variable can be changed to modify flags given to gcc.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
4.5. shell *ale-linter-options-shell*
|
||||
|
||||
g:ale_linters_sh_shell_default_shell *g:ale_linters_sh_shell_default_shell*
|
||||
|
||||
Type: |String|
|
||||
Default: The current shell (`$SHELL`) or `'bash'` if that cannot be read.
|
||||
|
||||
When ALE runs the linter for shells with the `-n` flag, it will attempt to
|
||||
read the shell from the shebang (`#!`) line from the shell script to
|
||||
determine the shell program to run. When this detection fails, this variable
|
||||
will be used instead.
|
||||
|
||||
===============================================================================
|
||||
5. API *ale-api*
|
||||
|
||||
|
|
Reference in a new issue