From cbc029b2b832e6d70d95e6cf810ab6252b42e643 Mon Sep 17 00:00:00 2001 From: Holden Date: Fri, 7 Dec 2018 18:04:28 -0500 Subject: [PATCH 1/5] Add initial support for settings to overwrite ale shell --- autoload/ale/job.vim | 12 +++++++++--- doc/ale.txt | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim index 0117c7dd..d4771842 100644 --- a/autoload/ale/job.vim +++ b/autoload/ale/job.vim @@ -11,6 +11,12 @@ " A setting for wrapping commands. let g:ale_command_wrapper = get(g:, 'ale_command_wrapper', '') +" A setting for the shell used to execute commands +let g:ale_shell = get(g:, 'ale_shell', &shell) + +" A setting for the arguments we pass to the shell when executing commands +let g:ale_shell_arguments = get(g:, 'ale_shell_arguments', &shellcmdflag) + if !has_key(s:, 'job_map') let s:job_map = {} endif @@ -188,11 +194,11 @@ function! ale#job#PrepareCommand(buffer, command) abort return 'cmd /s/c "' . l:command . '"' endif - if &shell =~? 'fish$\|pwsh$' - return ['/bin/sh', '-c', l:command] + if g:ale_shell =~? 'fish$\|pwsh$' + return ['/bin/sh', g:ale_shell_arguments, l:command] endif - return split(&shell) + split(&shellcmdflag) + [l:command] + return [g:ale_shell] + split(g:ale_shell_arguments) + [l:command] endfunction " Start a job with options which are agnostic to Vim and NeoVim. diff --git a/doc/ale.txt b/doc/ale.txt index 1a37f73f..7fbaa0df 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1984,6 +1984,24 @@ g:ale_windows_node_executable_path *g:ale_windows_node_executable_path* scripts are executed with whatever executable is configured with this setting. +g:ale_shell *g:ale_shell* + + Type: |String| + Default: `'&shell'` + + This variable is used to determine which shell ale will use to execute + commands. This variables defaults to the value of the vim option '&shell' + which corresponds to the $SHELL environment variable. For example + if `$SHELL == '/bin/bash'`, but you want to use zsh, set `g:ale_shell = '/bin/zsh'.` + +g:ale_shell_arguments *g:ale_shell_arguments* + + Type: |String| + Default: `'&shellcmdflag'` + + This variable is used to determine what commands vim will pass to the shell + to execute it's commands. By default, `&shellcmdflag` would be set to the + value of '`-c'`. ------------------------------------------------------------------------------- 6.1. Highlights *ale-highlights* From c499825a0bc3f27d728e42b61ee25ec9a06644fa Mon Sep 17 00:00:00 2001 From: Holden Date: Fri, 28 Dec 2018 11:58:55 -0500 Subject: [PATCH 2/5] add tests for ale_shell option --- doc/ale.txt | 4 ++-- test/fix/test_ale_fix.vader | 2 +- test/lsp/test_lsp_command_formatting.vader | 2 +- test/test_prepare_command.vader | 7 +++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/ale.txt b/doc/ale.txt index 1535d89e..f6063718 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1990,7 +1990,7 @@ g:ale_windows_node_executable_path *g:ale_windows_node_executable_path* scripts are executed with whatever executable is configured with this setting. -g:ale_shell *g:ale_shell* +g:ale_shell *g:ale_shell* Type: |String| Default: `'&shell'` @@ -2000,7 +2000,7 @@ g:ale_shell *g:ale_shell* which corresponds to the $SHELL environment variable. For example if `$SHELL == '/bin/bash'`, but you want to use zsh, set `g:ale_shell = '/bin/zsh'.` -g:ale_shell_arguments *g:ale_shell_arguments* +g:ale_shell_arguments *g:ale_shell_arguments* Type: |String| Default: `'&shellcmdflag'` diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index 90407681..ac15bc05 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -26,7 +26,7 @@ Before: augroup END if !has('win32') - let &shell = '/bin/bash' + let g:ale_shell = '/bin/bash' endif call ale#test#SetDirectory('/testplugin/test') diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader index 9721f37f..33928291 100644 --- a/test/lsp/test_lsp_command_formatting.vader +++ b/test/lsp/test_lsp_command_formatting.vader @@ -31,6 +31,6 @@ Execute(Command formatting should be applied correctly for LSP linters): \ g:args else AssertEqual - \ ['true', [&shell, '-c', '''true'' --foo']], + \ ['true', [g:ale_shell, '-c', '''true'' --foo']], \ g:args endif diff --git a/test/test_prepare_command.vader b/test/test_prepare_command.vader index 75e4c0c6..2bdfd2cb 100644 --- a/test/test_prepare_command.vader +++ b/test/test_prepare_command.vader @@ -4,6 +4,7 @@ Before: After: Restore + let g:ale_shell = &shell Execute(sh should be used when the shell is fish): if !has('win32') @@ -43,6 +44,7 @@ Execute(Other shells should be used when set): if !has('win32') let &shell = '/bin/bash' let &shellcmdflag = '-c' + let g:ale_shell = &shell AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar') endif @@ -54,3 +56,8 @@ Execute(cmd /s/c as a string should be used on Windows): AssertEqual 'cmd /s/c "foobar"', ale#job#PrepareCommand(bufnr(''), 'foobar') endif + +Execute(Setting ale_shell should cause ale#job#PrepareCommand to use set shell): + let g:ale_shell = '/foo/bar' + + AssertEqual ['/foo/bar', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar") From 3ec20a730d1c6485ab28704f930a61c6ba426b27 Mon Sep 17 00:00:00 2001 From: Holden Date: Fri, 28 Dec 2018 12:35:57 -0500 Subject: [PATCH 3/5] address PR feedback by fixing docs and hardcoding bash to use -c on fish and pwsh environments --- autoload/ale/job.vim | 2 +- doc/ale.txt | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim index d4771842..63697c4a 100644 --- a/autoload/ale/job.vim +++ b/autoload/ale/job.vim @@ -195,7 +195,7 @@ function! ale#job#PrepareCommand(buffer, command) abort endif if g:ale_shell =~? 'fish$\|pwsh$' - return ['/bin/sh', g:ale_shell_arguments, l:command] + return ['/bin/sh', '-c', l:command] endif return [g:ale_shell] + split(g:ale_shell_arguments) + [l:command] diff --git a/doc/ale.txt b/doc/ale.txt index f6063718..7b5fa624 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1999,6 +1999,12 @@ g:ale_shell *g:ale_shell* commands. This variables defaults to the value of the vim option '&shell' which corresponds to the $SHELL environment variable. For example if `$SHELL == '/bin/bash'`, but you want to use zsh, set `g:ale_shell = '/bin/zsh'.` + If this option is set to either `fish` or `pwsh` (either by default or set + with this command), ale will still execute commands with `bin/sh`. + + Please note - if you are using this option you should consider additionally + setting `g:ale``g:ale_shell_arguments` since the default values for that + option might be incompatable with the newly set shell. g:ale_shell_arguments *g:ale_shell_arguments* @@ -2007,7 +2013,8 @@ g:ale_shell_arguments *g:ale_shell_arguments* This variable is used to determine what commands vim will pass to the shell to execute it's commands. By default, `&shellcmdflag` would be set to the - value of '`-c'`. + value of '`-c'`. Similar to `g:ale_shell`, if the shell is set to either + `fish` or `pwsh`, `g:ale_shell_arguments` will no be used. ------------------------------------------------------------------------------- 6.1. Highlights *ale-highlights* From 8550fa605958bff90d727cde949ae2b06b870f8f Mon Sep 17 00:00:00 2001 From: Holden Date: Fri, 28 Dec 2018 12:51:01 -0500 Subject: [PATCH 4/5] fix tests on windows --- test/test_prepare_command.vader | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_prepare_command.vader b/test/test_prepare_command.vader index 2bdfd2cb..660235cc 100644 --- a/test/test_prepare_command.vader +++ b/test/test_prepare_command.vader @@ -58,6 +58,8 @@ Execute(cmd /s/c as a string should be used on Windows): endif Execute(Setting ale_shell should cause ale#job#PrepareCommand to use set shell): - let g:ale_shell = '/foo/bar' + if !has('win32') + let g:ale_shell = '/foo/bar' - AssertEqual ['/foo/bar', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar") + AssertEqual ['/foo/bar', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), "foobar") + endif From 5f613a5fd69f4135d892a71b1f825f062ff45758 Mon Sep 17 00:00:00 2001 From: Holden Date: Wed, 2 Jan 2019 19:05:51 -0500 Subject: [PATCH 5/5] change ale to use value of g:ale_shell regardless of what it is --- autoload/ale/job.vim | 30 +++++++++++++++------- doc/ale.txt | 22 ++++++++-------- test/fix/test_ale_fix.vader | 2 +- test/lsp/test_lsp_command_formatting.vader | 2 +- test/test_prepare_command.vader | 2 +- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim index 63697c4a..1af95049 100644 --- a/autoload/ale/job.vim +++ b/autoload/ale/job.vim @@ -12,10 +12,10 @@ let g:ale_command_wrapper = get(g:, 'ale_command_wrapper', '') " A setting for the shell used to execute commands -let g:ale_shell = get(g:, 'ale_shell', &shell) +let g:ale_shell = get(g:, 'ale_shell', v:null) " A setting for the arguments we pass to the shell when executing commands -let g:ale_shell_arguments = get(g:, 'ale_shell_arguments', &shellcmdflag) +let g:ale_shell_arguments = get(g:, 'ale_shell_arguments', v:null) if !has_key(s:, 'job_map') let s:job_map = {} @@ -190,15 +190,27 @@ function! ale#job#PrepareCommand(buffer, command) abort " NeoVim handles this issue automatically if the command is a String, " but we'll do this explicitly, so we use the same exact command for both " versions. - if has('win32') - return 'cmd /s/c "' . l:command . '"' - endif + if g:ale_shell is v:null + if has('win32') + return 'cmd /s/c "' . l:command . '"' + endif - if g:ale_shell =~? 'fish$\|pwsh$' - return ['/bin/sh', '-c', l:command] - endif + if &shell =~? 'fish$\|pwsh$' + return ['/bin/sh', '-c', l:command] + endif - return [g:ale_shell] + split(g:ale_shell_arguments) + [l:command] + return split(&shell) + split(&shellcmdflag) + [l:command] + else + if has('win32') + return g:ale_shell . l:command . '"' + endif + + let l:shell_arguments = g:ale_shell_arguments is v:null + \ ? &shellcmdflag + \ : g:ale_shell_arguments + + return split(g:ale_shell) + split(l:shell_arguments) + [l:command] + endif endfunction " Start a job with options which are agnostic to Vim and NeoVim. diff --git a/doc/ale.txt b/doc/ale.txt index 7b5fa624..a827e77a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1993,14 +1993,17 @@ g:ale_windows_node_executable_path *g:ale_windows_node_executable_path* g:ale_shell *g:ale_shell* Type: |String| - Default: `'&shell'` + Default: not set This variable is used to determine which shell ale will use to execute - commands. This variables defaults to the value of the vim option '&shell' - which corresponds to the $SHELL environment variable. For example - if `$SHELL == '/bin/bash'`, but you want to use zsh, set `g:ale_shell = '/bin/zsh'.` - If this option is set to either `fish` or `pwsh` (either by default or set - with this command), ale will still execute commands with `bin/sh`. + commands. By default this variable is undefined, meaning that ALE will use + it's default behavior. Which is to run shells via the shell determined by + the `&shell` vim variable, with the arguments `&shellcmdflag`. Ale will fall + back to using `/bin/sh`if it detects the underlying `&shell`is either `fish` + or `pwsh`. However, if you set this variable ALE will no longer fall back to + other shells, meaning if you wanted to use `fish` you could do so via this + option. For example if `$SHELL == '/bin/bash'`, but you want to use zsh, + set `g:ale_shell = '/bin/zsh'. Please note - if you are using this option you should consider additionally setting `g:ale``g:ale_shell_arguments` since the default values for that @@ -2009,12 +2012,11 @@ g:ale_shell *g:ale_shell* g:ale_shell_arguments *g:ale_shell_arguments* Type: |String| - Default: `'&shellcmdflag'` + Default: not set This variable is used to determine what commands vim will pass to the shell - to execute it's commands. By default, `&shellcmdflag` would be set to the - value of '`-c'`. Similar to `g:ale_shell`, if the shell is set to either - `fish` or `pwsh`, `g:ale_shell_arguments` will no be used. + to execute it's commands. If this command is not set, but g:ale_shell is + set, ale will use `&shellcmdflag` as command arguments. ------------------------------------------------------------------------------- 6.1. Highlights *ale-highlights* diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index ac15bc05..90407681 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -26,7 +26,7 @@ Before: augroup END if !has('win32') - let g:ale_shell = '/bin/bash' + let &shell = '/bin/bash' endif call ale#test#SetDirectory('/testplugin/test') diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader index 33928291..9721f37f 100644 --- a/test/lsp/test_lsp_command_formatting.vader +++ b/test/lsp/test_lsp_command_formatting.vader @@ -31,6 +31,6 @@ Execute(Command formatting should be applied correctly for LSP linters): \ g:args else AssertEqual - \ ['true', [g:ale_shell, '-c', '''true'' --foo']], + \ ['true', [&shell, '-c', '''true'' --foo']], \ g:args endif diff --git a/test/test_prepare_command.vader b/test/test_prepare_command.vader index 660235cc..f90c881b 100644 --- a/test/test_prepare_command.vader +++ b/test/test_prepare_command.vader @@ -4,7 +4,7 @@ Before: After: Restore - let g:ale_shell = &shell + let g:ale_shell = v:null Execute(sh should be used when the shell is fish): if !has('win32')