skywind3000 / asyncrun.vim

:rocket: Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
https://www.vim.org/scripts/script.php?script_id=5431
MIT License
1.84k stars 109 forks source link

[nvim] Changing shell options on windows breaks AsyncRun #281

Open mynamedjef opened 7 months ago

mynamedjef commented 7 months ago

Using this minimal setup and neovim:

filetype plugin indent on
filetype plugin on

call plug#begin()
Plug 'skywind3000/asyncrun.vim'
call plug#end()

let &shell = executable('pwsh') ? 'pwsh' : 'powershell'
let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
let &shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait'
let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
set shellquote= shellxquote=

When I run :AsyncRun, I get something like this (python x.py should just output 'ok'):

|| [python x.py]
|| C:\Users\User\AppData\Local\Temp\nvim.0\7bpwQs\asyncrun.cmd
|| [Finished in 1 seconds]

Taking a look at asyncrun.cmd:

@echo off
call %VIM_COMMAND% 
set VIM_EXITCODE=%ERRORLEVEL%
call %VIM_PAUSE% 
exit %VIM_EXITCODE%

Removing shell commands (from let &shell to set shellquote), makes AsyncRun work correctly. My logic is that powershell doesn't invoke asyncrun.cmd correctly. Is there a fix for this?

skywind3000 commented 7 months ago

By default, asyncrun uses shell and shellcmdflag to run command. Changing them may cause issues.

Solution: specify dedicated shell option for asyncrun:

let g:asyncrun_shell = 'c:\windows\system32\cmd.exe'
let g:asyncrun_shellflag = '/c'
mynamedjef commented 7 months ago

Thanks for quick response. Tried your suggestion, but the problem is identical. Is there a way to set up default shellredir, shellpipe, shellquote and shellxquote? Since they seem to be important too

Mitch6886 commented 3 months ago

Hey I have made a pull request to allow changing the shell on windows with neo-vim,

https://github.com/skywind3000/asyncrun.vim/pull/287

To enable using cmd for asyncrun

let g:asyncrun_shell = 'c:\windows\system32\cmd.exe'
let g:asyncrun_shellflag = '/c'