Fix Support for PowerShell under Windows with VIM 8+#1326
Conversation
|
Nice fix — making the shell explicit in s:with_cd is definitely the right approach. It solved all my vim 8+ problems with PowerShell under Windows. I hope it will be implemented soon. For completeness and consistency, consider passing {'shell': 'cmd.exe'} to s:with_cd() in s:bang() as well, though I don't think it is really necessary. This is because I don't know whether this function is ever used under Windows and, whether it will work anyway, taking into account the FIXME remark. Since in s:bang() the command is executed via a batch file under Windows, the command shell will be cmd.exe even when executed under PowerShell. So to prevent PowerShell type commands in a batch file, I would suggest the following change on line 1000: let cmd = a:0 ? s:with_cd(a:cmd, a:1, {'shell': s:is_win ? 'cmd.exe' : &shell}) : a:cmd |
|
I have made your suggested update, but I'm not sure how to test it. Would you know? Or are you ok with accepting the change without testing? |
|
Sorry, there seems to be some merge problem now. Has the master changed in the meantime? I do not know how to test this. I had fixed the same issues as you did, but discovered your solutions are much better. Since the API of |
There was a problem hiding this comment.
Pull request overview
Fixes vim-plug command failures (PlugInstall/Update/Clean/Status/Diff) on Windows when &shell is set to PowerShell under Vim 8+. The issue had two roots: a bug in Vim's system() for compound PowerShell commands (resolved by patch-9.2.6), and a mismatch in s:spawn's vim8 branch where the actual command was escaped for cmd.exe while s:with_cd's cd prefix was escaped for PowerShell.
Changes:
- Refactored
s:with_cdto accept an options dict (shell,script) instead of a singlescriptboolean, allowing callers to specify which shell the resulting compound command will run in. - Added a
& { ... }block wrapper around PowerShell compound commands when the running Vim lacks patch-9.2.6, to work around thesystem()bug. - Updated callers (
s:bang,s:spawnvim8 branch,s:system) to pass the correct shell for the context (e.g.cmd.exeon Windows fors:bangsince it goes through a.batfile, and fors:spawnsince it invokescmd /s /c).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
It occurred to me that in the function if a:0 > 0
let cmd = s:with_cd(cmd, a:1, {'script': type(a:cmd) != s:TYPE.list})
endif
if s:is_win && type(a:cmd) != s:TYPE.list
let [batchfile, cmd] = s:batchfile(cmd)
endifTo prevent that a PowerShell style command would get into a batch file, you could for example do it like this: if a:0 > 0 && s:is_win && type(a:cmd) != s:TYPE.list
let cmd = s:with_cd(cmd, a:1, {'shell': 'cmd.exe'})
elseif a:0 > 0
let cmd = s:with_cd(cmd, a:1, {'script': type(a:cmd) != s:TYPE.list})
endif
if s:is_win && type(a:cmd) != s:TYPE.list
let [batchfile, cmd] = s:batchfile(cmd)
endif |
The following 'vim-plug' commands would fail and/or display errors
when executed by VIM 8+ on a Windows platform with the 'shell' option
set to 'powershell' or 'pwsh':
- PlugInstall
- PlugUpdate
- PlugClean
- PlugStatus
- PlugDiff
There were two causes for these errors:
- A bug in VIM itself (resolved by patch 9.2.6) with how compound
PowerShell commands are handled by the 'system()' vimscript
function.
- A bug in the 's:vim8' branch of the private 'vim-plug' function
's:spawn()' where the actual command to be executed was escaped
for 'cmd.exe' but the 'cd' prefix added by 's:with_cd()" was escaped
for PowerShell.
|
I have fixed the issue you identified with I also verified my previous Are you still have merge problems? I have been amending my commit in place and force-pushing the changes. So you may need to do a fresh checkout of my branch rather than simply pulling it. |
|
I'm not a Windows user so I cannot reproduce the problem and verify the fix, but the patch itself looks solid. Let me know if you think it's ready for merge. |
|
The patch is ready for merging. Thanks. |
|
Merged, thanks! |
The following 'vim-plug' commands would fail and/or display errors when executed on by VIM 8+ on a Windows platform with the 'shell' option set to 'powershell' or 'pwsh':
There were two causes for these errors:
Describe the details of your PR ...