Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ale option to override default shell used by ale #2167

Merged
merged 6 commits into from
Jan 3, 2019

Conversation

stegmanh
Copy link

This PR adds the g:ale_shell and g:ale_shell_argument options. Allowing the user to customize which shell ale will use to execute commands and allowing the user to specify any additional arguments they wish to pass to the execute function.

The reasoning for this change it to address an issue that came up in #1968. The TL;DR is that there are some instances where Neovim attempts to run a command via zsh and it fails due to odd argument passing, which can be fixed by just using bash to run the commands.

By default the g:ale_shell option is set to the &shell vim variable. And the g:ale_shell_argument option is set to -c as was default in ale.

Files changed in this PR:

  • autoload/ale/job.vim - Add support for g_ale_shell and g:ale_shell_argument commands and use those when running commands
  • doc/ale.txt - Add documentation for new options
  • test/* - Fix tests

@@ -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$'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this should be documented in the section for g:ale_shell

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this to be hardcoded '-c' to avoid conflicts with non-sh-compatible shells; because sh is standardized we know we can pass -c to it.

doc/ale.txt Outdated
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'.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add in a comment to suggest using g:ale_shell_arguments if overriding this, as g:ale_shell_arguments can pull incompatible flags from &shellcmdflag even if the user changes shell

@stegmanh
Copy link
Author

Thanks for reviewing that @RyanSquared! I just pushed a PR that addressed those comments. I think I might need to take a look at the appveyor logs though. That build appears to be failing

@RyanSquared
Copy link
Member

It breaks due to: https://github.com/w0rp/ale/blob/3ec20a730d1c6485ab28704f930a61c6ba426b27/autoload/ale/job.vim#L194

@w0rp both lists and strings are returned from ale#job#PrepareCommand - is that intentional, and if so, can that behavior be changed to be consistent?

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of replacing the built in variables with configurable ones which default to the Vim variables, make it so the default for the shell option is empty or undefined, and defining the option completely replaces all of the behavior, including the checks for cmd on Windows, fish, etc. Update the documentation to note that if you change the option, you're essentially on your own after that. You can default the shell options to the Vim variable.

If we do all of that, that will allow people to replace their shell on Windows, to use some hack or other to get fish to work, etc.

return ['/bin/sh', '-c', l:command]
endif

return split(&shell) + split(&shellcmdflag) + [l:command]
return [g:ale_shell] + split(g:ale_shell_arguments) + [l:command]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be wise to stick with split() here. It's mentioned in Vim or NeoVim documentation somewhere, but I can't remember where right now.

@w0rp
Copy link
Member

w0rp commented Dec 29, 2018

It breaks due to:

ale/autoload/ale/job.vim

Line 194 in 3ec20a7
return 'cmd /s/c "' . l:command . '"'

@w0rp both lists and strings are returned from ale#job#PrepareCommand - is that intentional, and if so, can that behavior be changed to be consistent?

Yes. Windows needs Strings, Unix needs Lists. Windows is weird.

@w0rp
Copy link
Member

w0rp commented Dec 29, 2018

The deal with Lists not working on Windows is that the Windows shell has no general support for quoting shell arguments. For cmd, argument quoting is handled by the programs, instead of by the shell itself. This means that quoting arguments can sometimes result in say literally "foo" instead of foo for "foo". Windows is weird.

@stegmanh
Copy link
Author

Thanks for the review @w0rp. Ill make those changes

@RyanSquared
Copy link
Member

Relevant: #2175

@stegmanh
Copy link
Author

stegmanh commented Jan 3, 2019

Alright I think these changes are in the direction you were talking about @w0rp.

I was running into issues testing locally with the readfile command not being able to read a tmp file. Hopefully it doesn't come up in travis, but if it does Ill investigate further

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I'll take this, and I'll fix some of the formatting, which looks like it's already a bit wrong. I'll probably update the documentation so it's a bit less verbose, and I might make the variables unset instead of v:null.

@w0rp w0rp merged commit 7919db0 into dense-analysis:master Jan 3, 2019
@w0rp
Copy link
Member

w0rp commented Jan 3, 2019

Cheers! 🍻

@stegmanh
Copy link
Author

stegmanh commented Jan 3, 2019

Cool! Thanks for merging this & helping with improving the PR. I'll keep an eye out for your PR so I know how to do unset and better formatting in the future.

🍻

@hibachrach
Copy link
Contributor

I may be wrong here, but this may have broken tests on AppVeyor.

@RyanSquared
Copy link
Member

Correct:

    (5/5) [EXECUTE] (X) ['/foo/bar', '/c', 'foobar'] should be equal to ['/foo/bar', '-c', 'foobar']

@w0rp
Copy link
Member

w0rp commented Jan 4, 2019

Yeah, I broke it.

@w0rp
Copy link
Member

w0rp commented Jan 4, 2019

I pushed a commit which should fix that now. I'll keep an eye on the test results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants