vim-plug
vim-plug copied to clipboard
PlugClean crash with PowerShell
Explain the problem here ...
Here is my minimal _vimrc with shell is PowerShell
"General settings
syntax on
set nocompatible
set background=dark
set noswapfile
set linespace=8
set textwidth=120
set shell=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
When I use :PlugClean it crash and return
but delete
set shell=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
it's ok.
Vim version:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Aug 26 2021 22:02:38)
MS-Windows 64-bit GUI version with OLE support
Included patches: 1-3377
Compiled by appveyor@APPVYR-WIN
Huge version with GUI. Features included (+) or not (-):
+acl +cmdline_compl -ebcdic +insert_expand +mksession +popupwin +sound +textprop +wildignore
+arabic +cmdline_hist +emacs_tags +ipv6 +modify_fname -postscript +spell -tgetent +wildmenu
+autocmd +cmdline_info +eval +job +mouse +printer +startuptime +timers +windows
+autochdir +comments +ex_extra +jumplist +mouseshape +profile +statusline +title +writebackup
+autoservername +conceal +extra_search +keymap +multi_byte_ime/dyn +python/dyn -sun_workshop +toolbar -xfontset
+balloon_eval +cryptv -farsi +lambda +multi_lang +python3/dyn +syntax +user_commands -xim
-balloon_eval_term +cscope +file_in_path +langmap +mzscheme/dyn +quickfix +tag_binary +vartabs +xpm_w32
+browse +cursorbind +find_in_path +libcall +netbeans_intg +reltime -tag_old_static +vertsplit -xterm_save
++builtin_terms +cursorshape +float +linebreak +num64 +rightleft -tag_any_white +virtualedit
+byte_offset +dialog_con_gui +folding +lispindent +ole +ruby/dyn +tcl/dyn +visual
+channel +diff -footer +listcmds +packages +scrollbind -termguicolors +visualextra
+cindent +digraphs +gettext/dyn +localmap +path_extra +signs +terminal +viminfo
+clientserver +directx -hangul_input +lua/dyn +perl/dyn +smartindent -termresponse +vreplace
+clipboard -dnd +iconv/dyn +menu +persistent_undo -sodium +textobjects -vtp
system vimrc file: "$VIM\vimrc"
user vimrc file: "$HOME\_vimrc"
2nd user vimrc file: "$HOME\vimfiles\vimrc"
3rd user vimrc file: "$VIM\_vimrc"
user exrc file: "$HOME\_exrc"
2nd user exrc file: "$VIM\_exrc"
system gvimrc file: "$VIM\gvimrc"
user gvimrc file: "$HOME\_gvimrc"
2nd user gvimrc file: "$HOME\vimfiles\gvimrc"
3rd user gvimrc file: "$VIM\_gvimrc"
defaults file: "$VIMRUNTIME\defaults.vim"
system menu file: "$VIMRUNTIME\menu.vim"
Compilation: cl -c /W3 /GF /nologo -I. -Iproto -DHAVE_PATHDEF -DWIN32 -DFEAT_CSCOPE -DFEAT_TERMINAL -DFEAT_SOUND -DFEAT_NETBEANS_INTG -DFEAT_JOB_CHANNEL -DFEAT_IPV6 -DFEAT_XPM_W32 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 /source-charset:utf-8 /MP -DHAVE_STDINT_H /Ox /GL -DNDEBUG /Zl /MT /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE -DFEAT_OLE -DFEAT_MBYTE_IME -DDYNAMIC_IME -DFEAT_GUI_MSWIN -DFEAT_DIRECTX -DDYNAMIC_DIRECTX -DFEAT_DIRECTX_COLOR_EMOJI -DDYNAMIC_ICONV -DDYNAMIC_GETTEXT -DFEAT_TCL -DDYNAMIC_TCL -DDYNAMIC_TCL_DLL=\"tcl86t.dll\" -DDYNAMIC_TCL_VER=\"8.6\" -DFEAT_LUA -DDYNAMIC_LUA -DDYNAMIC_LUA_DLL=\"lua53.dll\" -DFEAT_PYTHON -DDYNAMIC_PYTHON -DDYNAMIC_PYTHON_DLL=\"python27.dll\" -DFEAT_PYTHON3 -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL=\"python39.dll\" -DFEAT_MZSCHEME -I "C:\Program Files\Racket\include" -DMZ_PRECISE_GC -DDYNAMIC_MZSCHEME -DDYNAMIC_MZSCH_DLL=\"libracket3m_a36fs8.dll\" -DDYNAMIC_MZGC_DLL=\"libracket3m_a36fs8.dll\" -DFEAT_PERL -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DDYNAMIC_PERL -DDYNAMIC_PERL_DLL=\"perl528.dll\" -DFEAT_RUBY -DDYNAMIC_RUBY -DDYNAMIC_RUBY_DLL=\"x64-msvcrt-ruby240.dll\" -DRUBY_VERSION=24 -DFEAT_HUGE /Fd.\ObjGXOULYHTRZAMD64/ /Zi
Linking: link /nologo /opt:ref /LTCG:STATUS /HIGHENTROPYVA:NO oldnames.lib kernel32.lib advapi32.lib shell32.lib gdi32.lib comdlg32.lib ole32.lib netapi32.lib uuid.lib /machine:AMD64 gdi32.lib version.lib winspool.lib comctl32.lib advapi32.lib shell32.lib netapi32.lib /machine:AMD64 libcmt.lib oleaut32.lib user32.lib /nodefaultlib:lua53.lib /STACK:8388608 /nodefaultlib:python27.lib /nodefaultlib:python39.lib "C:\Tcl\lib\tclstub86.lib" winmm.lib WSock32.lib Ws2_32.lib xpm\x64\lib-vc14\libXpm.lib /PDB:gvim.pdb -debug
- Type:
- [X] Bug
- OS:
- [X] Windows
- Vim:
- [X] GVim
I came across the same problem. after i had been debugging plug.vim for at least 3 hours. finally, i found where the bug is. your powershell's version should be lower than 7.0, and it cant't recognize the "&&" in external command "cd /d ^"path^" && & commands" which follow the argument "-command"(the similar problem is "cd /c", even higher than 7.0,powershell doesn't recognize the "/c") , the bug is in "plug.vim ->s:clean() -> s:git_validate() -> s:system() ". that's it. i don't know how vim-plug solve the difference between varieties of shell, so asking author to solve the problem and waiting are the only things we can do.
finally, i found where the bug is. your powershell's version should be lower than 7.0
Windows is shipped with powershell 5.1, also I'm using C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
with $PSVersionTable. It's already lower than 7.0.
PS C:\Users\sofia> echo $PSVersionTable
Name Value
---- -----
PSVersion 5.1.22621.1778
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.1778
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
,powershell doesn't recognize the "/c"
Yes, powershell syntax try to follow Unix style, /c
is flag of batch so it can't run in powershell.
I was searching for problem in s:system
and I added echo to debug the underlying command.
function! s:system(cmd, ...)
let batchfile = ''
try
let [sh, shellcmdflag, shrd] = s:chsh(1)
if type(a:cmd) == s:TYPE.list
" Neovim's system() supports list argument to bypass the shell
" but it cannot set the working directory for the command.
" Assume that the command does not rely on the shell.
if has('nvim') && a:0 == 0
return system(a:cmd)
endif
let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"shell": &shell, "script": 0})'))
echo 'line 1 ' . cmd
if s:is_powershell(&shell)
let cmd = '& ' . cmd
echo 'line 2 ' . cmd
endif
else
let cmd = a:cmd
endif
if a:0 > 0
let cmd = s:with_cd(cmd, a:1, type(a:cmd) != s:TYPE.list)
echo 'line 3 ' . cmd
endif
if s:is_win && type(a:cmd) != s:TYPE.list
let [batchfile, cmd] = s:batchfile(cmd)
echo cmd
endif
return system(cmd)
finally
let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd]
if s:is_win && filereadable(batchfile)
call delete(batchfile)
endif
endtry
endfunction
Run :PlugClean
and it returns
line 1 git rev-list --count --left-right HEAD...origin/master
line 2 & git rev-list --count --left-right HEAD...origin/master
line 3 cd /d ^"C:\Users\sofia\vimfiles\plugged\vim-surround\^" && & git rev-list --count --left-right HEAD...origin/master
Error detected while processing function <SNR>3 clean[13]..<SNR>3_ git validate[36]..<SNR>3_system[34]..function <SNR>3 clean[13]..<SNR>3_git_validate[36]..<SNR>3_system:
line 28:
E282: cannot read from "C:\Users\sofia\AppData\Local\Temp\VNJBBA.tmp"
Press ENTER or type command to continuef]
It seems line 3 cd /d ^"C:\Users\sofia\vimfiles\plugged\vim-surround\^" && & git rev-list --count --left-right HEAD...origin/master
has weird syntax with first part cd /d ^"C:\Users\sofia\vimfiles\plugged\vim-surround\^"
in cmd.exe but second part & git rev-list --count --left-right
is powershell.
I tried to remove &
so it should be homogeneous but it didn't work.
I have shell pwsh
" ~/_vimrc
if has('win32')
set shell=pwsh
let &shellcmdflag='-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command'
if !has('patch-8.2.3079')
let &shellcmdflag = ' ' . &shellcmdflag
endif
let &shellxquote='"'
set shellxescape= shellquote= noshellslash
let &shellredir = '2>&1 | Out-File -Encoding Default %s; exit $LastExitCode'
endif
I had to modify plug.vim
for PlugStatus
and PlugInstall
to work.
-
cd
in powershell does not have/d
flag
" function! s:with_cd(cmd, dir, ...)
...
return printf('cd%s %s && %s', s:is_powershell(&shell) ? '' : s:is_win ? ' /d' : '', plug#shellescape(a:dir, {'script': script}), a:cmd)
...
- In
shellescape
function setshell
" function! plug#shellescape(arg, ...)
...
let shell = 'pwsh'" get(opts, 'shell', s:is_win ? 'cmd.exe' : 'sh')
...
- In
spawn
function added powershell for job arguments. Propably, better to use&shellcmdflag
variable
" function! s:spawn(name, cmd, opts)
...
let argv = s:is_powershell(&shell)
\ ? ['pwsh', '-NoLogo', '-NoProfile', '-ExecutionPolicy', 'RemoteSigned', '-Command', '"'.cmd.'"']
\ : s:is_win
\ ? ['cmd', '/s', '/c', '"'.cmd.'"']
\ : ['sh', '-c', cmd]
...