From 9d52d968db9b6cfdc493e1418348a3ff26177230 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 9 Oct 2016 19:32:01 +0100 Subject: [PATCH 1/4] #69 Improve shell detection --- ale_linters/sh/shell.vim | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ale_linters/sh/shell.vim b/ale_linters/sh/shell.vim index f5987c03..ce8aa6c8 100644 --- a/ale_linters/sh/shell.vim +++ b/ale_linters/sh/shell.vim @@ -14,20 +14,18 @@ if !exists('g:ale_linters_sh_shell_default_shell') 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(bangmatch) > 0 - let shell = bangmatch[1] - endif + if len(banglines) == 1 && banglines[0] =~# '^#!' + for possible_shell in ['bash', 'tcsh', 'csh', 'zsh', 'sh'] + if banglines[0] =~# 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) From 2d32c312059e10da03e8f0b9627b2f9ee49bd6bf Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 9 Oct 2016 19:41:27 +0100 Subject: [PATCH 2/4] Handle arguments to shells in shebang lines too. --- ale_linters/sh/shell.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ale_linters/sh/shell.vim b/ale_linters/sh/shell.vim index ce8aa6c8..979bda3f 100644 --- a/ale_linters/sh/shell.vim +++ b/ale_linters/sh/shell.vim @@ -18,8 +18,11 @@ function! ale_linters#sh#shell#GetExecutable(buffer) " Take the shell executable from the hashbang, if we can. if len(banglines) == 1 && banglines[0] =~# '^#!' + " Remove options like -e, etc. + let line = substitute(banglines[0], '--\?[a-zA-Z0-9]\+', '', 'g') + for possible_shell in ['bash', 'tcsh', 'csh', 'zsh', 'sh'] - if banglines[0] =~# possible_shell . '\s*$' + if line =~# possible_shell . '\s*$' return possible_shell endif endfor From b5e4538699f2850ca9c9ebfefad8fcbd18fe5eba Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 9 Oct 2016 20:39:14 +0100 Subject: [PATCH 3/4] #69 Change the default shell for shell linting --- ale_linters/sh/shell.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ale_linters/sh/shell.vim b/ale_linters/sh/shell.vim index 979bda3f..8b45c49b 100644 --- a/ale_linters/sh/shell.vim +++ b/ale_linters/sh/shell.vim @@ -10,7 +10,11 @@ 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) From 07599d006ca35fe5272fd0d5decb25d18e3086a8 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 9 Oct 2016 20:45:51 +0100 Subject: [PATCH 4/4] Document the default shell option --- doc/ale.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/doc/ale.txt b/doc/ale.txt index 6772c25a..4f05d20b 100644 --- a/doc/ale.txt +++ b/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| @@ -286,6 +287,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*