vim-plug icon indicating copy to clipboard operation
vim-plug copied to clipboard

`:PlugStatus`, and I guess basically any command that use `s:with_cd()` internally, won't work when using powershell

Open dougaak opened this issue 1 year ago • 1 comments

Here is a raw display of the error: Image

The log produced by vim itself shows that the actual command getting execute contains parentheses:

Calling shell to execute: "(cd 'd:\\Users\\t0261309\\DEV_COLLECTION\\vim\\vimfiles\\plugged\\vim-code-dark\\' ; & git rev-list --count --left-right HEAD...origin/master) 2>&1 | Out-File -Encoding UTF8 d:\Users\t0261309\AppData\Local\Temp\V7NC049.tmp"

Based on the source code implementation of s:with_cd() I can see that for powershell, ; is used to separate two commands. However, the subsequent vim built-in call system() will internally add parentheses around the command, and that breaks powershell as a ; in parentheses is not allowed.

I believe the last E282 error is irrelevant for it is simply because the command is not executed at all and thus no tmp file is created.

A simple fix that I can think of is wrapping the whole cmd with $(...), where ; can live in, and after the system() wrapping, ($(...;...)) works.

dougaak avatar Apr 25 '25 09:04 dougaak

@dougaak, you were right. I solved it as follows. The original lines 2374 - 2376:

    if a:0 > 0
      let cmd = s:with_cd(cmd, a:1, type(a:cmd) != s:TYPE.list)
    endif

Added a fix for PowerShell:

    if a:0 > 0
      let cmd = s:with_cd(cmd, a:1, type(a:cmd) != s:TYPE.list)
      if s:is_powershell(&shell)
        let cmd = '$(' . cmd . ')'
      endif
    endif

And that solved the problem

HaaiHenkie avatar May 11 '26 23:05 HaaiHenkie