1111" 2024 Sep 23 by Vim Project: runtime dir selection fix (#15722)
1212" autoloading search path fix
1313" substitution of hardcoded commands with global variables
14+ " 2024 Nov 12 by Vim Project: fix problems on Windows (#16036)
1415" }}}
1516"
1617" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
2728 echoerr " GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
2829 finish
2930endif
30- if v: version < 702
31+ if v: version < 901
3132 echohl WarningMsg
32- echo " ***warning*** this version of GetLatestVimScripts needs vim 7.2 "
33+ echo " ***warning*** this version of GetLatestVimScripts needs vim 9.1 "
3334 echohl Normal
3435 finish
3536endif
5758if ! exists (" g:GetLatestVimScripts_wget" )
5859 if executable (" wget" )
5960 let g: GetLatestVimScripts_wget= " wget"
61+ elseif executable (" curl.exe" )
62+ " enforce extension: windows powershell desktop version has a curl alias that hides curl.exe
63+ let g: GetLatestVimScripts_wget= " curl.exe"
6064 elseif executable (" curl" )
6165 let g: GetLatestVimScripts_wget= " curl"
6266 else
6973if ! exists (" g:GetLatestVimScripts_options" )
7074 if g: GetLatestVimScripts_wget == " wget"
7175 let g: GetLatestVimScripts_options= " -q -O"
72- elseif g: GetLatestVimScripts_wget == " curl"
76+ elseif g: GetLatestVimScripts_wget = ~ " curl"
7377 let g: GetLatestVimScripts_options= " -s -o"
7478 else
7579 let g: GetLatestVimScripts_options= " "
@@ -121,11 +125,14 @@ if g:GetLatestVimScripts_allowautoinstall
121125 let s: dotvim= s: is_windows ? " vimfiles" : " .vim"
122126
123127 if ! exists (" g:GetLatestVimScripts_mv" )
124- if s: is_windows && &shell !~ ' \cbash\|pwsh\|powershell'
128+ if &shell = ~? ' \<pwsh\>\|\<powershell\>'
129+ let g: GetLatestVimScripts_mv= " move -Force"
130+ elseif s: is_windows && &shell = ~? ' \<cmd\>'
125131 " windows (but not cygwin/bash)
126- let g: GetLatestVimScripts_mv= " move"
132+ let g: GetLatestVimScripts_mv= " move /Y "
127133 else
128- " unix
134+ " unix or cygwin bash/zsh
135+ " 'mv' overrides existing files without asking
129136 let g: GetLatestVimScripts_mv= " mv"
130137 endif
131138 endif
@@ -160,12 +167,6 @@ fun! getscript#GetLatestVimScripts()
160167 return
161168 endif
162169
163- " insure that fnameescape() is available
164- if ! exists (" *fnameescape" )
165- echoerr " GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
166- return
167- endif
168-
169170 " Find the .../GetLatest subdirectory under the runtimepath
170171 for datadir in split (&rtp ,' ,' ) + [' ' ]
171172 if isdirectory (datadir." /GetLatest" )
@@ -377,7 +378,16 @@ fun! s:GetOneScript(...)
377378 let t_ti = &t_ti
378379 let t_te = &t_te
379380 let rs = &rs
381+ let ssl = &ssl
382+
380383 set t_ti = t_te = nors
384+ " avoid issues with shellescape() on Windows
385+ if s: is_windows && &shell = ~? ' \<cmd\>'
386+ set noshellslash
387+ endif
388+
389+ " restore valures afterwards
390+ defer execute (" let @a = rega | let &t_ti = t_ti | let &t_te = t_te | let &rs = rs | let &ssl = ssl" )
381391
382392 " put current line on top-of-screen and interpret it into
383393 " a script identifier : used to obtain webpage
@@ -394,7 +404,6 @@ fun! s:GetOneScript(...)
394404 else
395405 let curline = getline (" ." )
396406 if curline = ~ ' ^\s*#'
397- let @a = rega
398407" call Dret("GetOneScript : skipping a pure comment line")
399408 return
400409 endif
@@ -429,7 +438,6 @@ fun! s:GetOneScript(...)
429438 " plugin author protection from downloading his/her own scripts atop their latest work
430439 if scriptid == 0 || srcid == 0
431440 " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
432- let @a = rega
433441" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
434442 return
435443 endif
@@ -497,7 +505,6 @@ fun! s:GetOneScript(...)
497505" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
498506 echomsg " ***warning*** couldn'" .' t find "Click on the package..." in description page for <' .aicmmnt." >"
499507" call Dret("GetOneScript : srch for /Click on the package/ failed")
500- let @a = rega
501508 return
502509 endif
503510" call Decho('found "Click on the package to download"')
@@ -513,7 +520,6 @@ fun! s:GetOneScript(...)
513520 let s: downerrors = s: downerrors + 1
514521" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
515522 echomsg " ***warning*** couldn'" .' t find "src_id=" in description page for <' .aicmmnt." >"
516- let @a = rega
517523" call Dret("GetOneScript : srch for /src_id/ failed")
518524 return
519525 endif
@@ -547,11 +553,11 @@ fun! s:GetOneScript(...)
547553" call Decho(".downloading new <".sname.">")
548554 echomsg " .downloading new <" .sname." >"
549555 if has (" win32" ) || has (" win16" ) || has (" win95" )
550- " call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)."|q ")
551- new |exe " silent r!" .g: GetLatestVimScripts_wget ." " .g: GetLatestVimScripts_options ." " .shellescape (sname)." " .shellescape (g: GetLatestVimScripts_downloadaddr .latestsrcid)|q
556+ " call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)."|bw! ")
557+ new |exe " silent r!" .g: GetLatestVimScripts_wget ." " .g: GetLatestVimScripts_options ." " .shellescape (sname)." " .shellescape (g: GetLatestVimScripts_downloadaddr .latestsrcid)|bw !
552558 else
553- " call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr) .latestsrcid
554- exe " silent !" .g: GetLatestVimScripts_wget ." " .g: GetLatestVimScripts_options ." " .shellescape (sname)." " .shellescape (g: GetLatestVimScripts_downloadaddr) .latestsrcid
559+ " call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)
560+ exe " silent !" .g: GetLatestVimScripts_wget ." " .g: GetLatestVimScripts_options ." " .shellescape (sname)." " .shellescape (g: GetLatestVimScripts_downloadaddr .latestsrcid)
555561 endif
556562
557563 " --------------------------------------------------------------------------
@@ -654,8 +660,8 @@ fun! s:GetOneScript(...)
654660 exe " silent !" .g: GetLatestVimScripts_mv ." " .shellescape (sname)." " .installdir
655661 endif
656662 if tgtdir != " plugin"
657- " call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/ ".shellescape(pname)." ".tgtdir)
658- exe " silent !" .g: GetLatestVimScripts_mv ." plugin/ " .shellescape (pname)." " .tgtdir
663+ " call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape("plugin/". pname)." ".tgtdir)
664+ exe " silent !" .g: GetLatestVimScripts_mv ." " .shellescape (" plugin/ " . pname)." " .tgtdir
659665 endif
660666
661667 " helptags step
@@ -680,13 +686,7 @@ fun! s:GetOneScript(...)
680686" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
681687 endif
682688
683- " restore options
684- let &t_ti = t_ti
685- let &t_te = t_te
686- let &rs = rs
687- let @a = rega
688689" call Dredir("BUFFER TEST (GetOneScript)","ls!")
689-
690690" call Dret("GetOneScript")
691691endfun
692692
0 commit comments