vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

getscript.vim (22174B)


      1 " ---------------------------------------------------------------------
      2 " getscript.vim
      3 "  Maintainer: This runtime file is looking for a new maintainer.
      4 "  Original Author: Charles E. Campbell
      5 "  Date:	Jan 21, 2014
      6 "  Version:	37
      7 "  Installing:	:help glvs-install
      8 "  Usage:	:help glvs
      9 "  Last Change:	{{{1
     10 "   2024 Sep 08 by Vim Project: several small fixes (#15640)
     11 "   2024 Sep 23 by Vim Project: runtime dir selection fix (#15722)
     12 "                               autoloading search path fix
     13 "                               substitution of hardcoded commands with global variables
     14 "   2024 Nov 12 by Vim Project: fix problems on Windows (#16036)
     15 "   2025 Feb 28 by Vim Project: add support for bzip3 (#16755)
     16 "   2025 May 11 by Vim Project: check network connectivity (#17249)
     17 "   2025 Dec 21 by Vim Project: make the wget check more robust (#18987)
     18 "   2026 May 20 by Vim Project: use correct shellescape() with ! command
     19 "  }}}
     20 "
     21 " GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
     22 "redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
     23 " ---------------------------------------------------------------------
     24 " Initialization:	{{{1
     25 " if you're sourcing this file, surely you can't be
     26 " expecting vim to be in its vi-compatible mode!
     27 if exists("g:loaded_getscript")
     28  finish
     29 endif
     30 let g:loaded_getscript= "v37"
     31 if &cp
     32  echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
     33  finish
     34 endif
     35 if v:version < 901
     36  echohl WarningMsg
     37  echo "***warning*** this version of GetLatestVimScripts needs vim 9.1"
     38  echohl Normal
     39  finish
     40 endif
     41 let s:keepcpo = &cpo
     42 set cpo&vim
     43 "DechoTabOn
     44 
     45 " ---------------------------
     46 " Global Variables: {{{1
     47 " ---------------------------
     48 " Cygwin Detection ------- {{{2
     49 if !exists("g:getscript_cygwin")
     50  if has("win32") || has("win95") || has("win64") || has("win16")
     51   if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
     52    let g:getscript_cygwin= 1
     53   else
     54    let g:getscript_cygwin= 0
     55   endif
     56  else
     57   let g:getscript_cygwin= 0
     58  endif
     59 endif
     60 
     61 " wget vs curl {{{2
     62 if !exists("g:GetLatestVimScripts_wget")
     63  if executable("wget.exe")
     64   " enforce extension: windows powershell desktop version has a wget alias that hides wget.exe
     65   let g:GetLatestVimScripts_wget= "wget.exe"
     66  elseif executable("wget")
     67   let g:GetLatestVimScripts_wget= "wget"
     68  elseif executable("curl.exe")
     69   " enforce extension: windows powershell desktop version has a curl alias that hides curl.exe
     70   let g:GetLatestVimScripts_wget= "curl.exe"
     71  elseif executable("curl")
     72   let g:GetLatestVimScripts_wget= "curl"
     73  else
     74   let g:GetLatestVimScripts_wget    = 'echo "GetLatestVimScripts needs wget or curl"'
     75   let g:GetLatestVimScripts_options = ""
     76  endif
     77 endif
     78 
     79 " options that wget and curl require:
     80 if !exists("g:GetLatestVimScripts_options")
     81  if g:GetLatestVimScripts_wget =~ "wget"
     82   let g:GetLatestVimScripts_options= "-q -O"
     83  elseif g:GetLatestVimScripts_wget =~ "curl"
     84   let g:GetLatestVimScripts_options= "-s -o"
     85  else
     86   let g:GetLatestVimScripts_options= ""
     87  endif
     88 endif
     89 
     90 " by default, allow autoinstall lines to work
     91 if !exists("g:GetLatestVimScripts_allowautoinstall")
     92  let g:GetLatestVimScripts_allowautoinstall= 1
     93 endif
     94 
     95 " set up default scriptaddr address
     96 if !exists("g:GetLatestVimScripts_scriptaddr")
     97  let g:GetLatestVimScripts_scriptaddr = 'https://www.vim.org/scripts/script.php?script_id='
     98 endif
     99 
    100 if !exists("g:GetLatestVimScripts_downloadaddr")
    101   let g:GetLatestVimScripts_downloadaddr = 'https://www.vim.org/scripts/download_script.php?src_id='
    102 endif
    103 
    104 " define decompression tools (on windows this allows redirection to wsl or git tools).
    105 " Note tar is available as builtin since Windows 11.
    106 if !exists("g:GetLatestVimScripts_bunzip2")
    107  let g:GetLatestVimScripts_bunzip2= "bunzip2"
    108 endif
    109 
    110 if !exists("g:GetLatestVimScripts_bunzip3")
    111  let g:GetLatestVimScripts_bunzip3= "bunzip3"
    112 endif
    113 
    114 if !exists("g:GetLatestVimScripts_gunzip")
    115  let g:GetLatestVimScripts_gunzip= "gunzip"
    116 endif
    117 
    118 if !exists("g:GetLatestVimScripts_unxz")
    119  let g:GetLatestVimScripts_unxz= "unxz"
    120 endif
    121 
    122 if !exists("g:GetLatestVimScripts_unzip")
    123  let g:GetLatestVimScripts_unzip= "unzip"
    124 endif
    125 
    126 "" For debugging:
    127 "let g:GetLatestVimScripts_wget    = "echo"
    128 "let g:GetLatestVimScripts_options = "options"
    129 
    130 " ---------------------------------------------------------------------
    131 " Check If AutoInstall Capable: {{{1
    132 let s:autoinstall= ""
    133 if g:GetLatestVimScripts_allowautoinstall
    134 
    135  let s:is_windows = has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")
    136  let s:dotvim= s:is_windows ? "vimfiles" : ".vim"
    137 
    138  if !exists("g:GetLatestVimScripts_mv")
    139   if &shell =~? '\<pwsh\>\|\<powershell\>'
    140    let g:GetLatestVimScripts_mv= "move -Force"
    141   elseif s:is_windows && &shell =~? '\<cmd\>'
    142    " windows (but not cygwin/bash)
    143    let g:GetLatestVimScripts_mv= "move /Y"
    144   else
    145    " unix or cygwin bash/zsh
    146    " 'mv' overrides existing files without asking
    147     let g:GetLatestVimScripts_mv= "mv"
    148   endif
    149  endif
    150 
    151  if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
    152   let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
    153  elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
    154   let s:autoinstall= $HOME."/".s:dotvim
    155  endif
    156 endif
    157 
    158 " ---------------------------------------------------------------------
    159 "  Public Interface: {{{1
    160 com!        -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
    161 com!        -nargs=0 GetScript           call getscript#GetLatestVimScripts()
    162 silent! com -nargs=0 GLVS                call getscript#GetLatestVimScripts()
    163 
    164 " ---------------------------------------------------------------------
    165 " GetLatestVimScripts: this function gets the latest versions of {{{1
    166 "                      scripts based on the list in
    167 "   (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
    168 fun! getscript#GetLatestVimScripts()
    169 
    170   if executable(g:GetLatestVimScripts_wget) != 1
    171    echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
    172    return
    173   endif
    174 
    175   " Find the .../GetLatest subdirectory under the runtimepath
    176   for datadir in split(&rtp,',') + ['']
    177    if isdirectory(datadir."/GetLatest")
    178     let datadir= datadir . "/GetLatest"
    179     break
    180    endif
    181    if filereadable(datadir."GetLatestVimScripts.dat")
    182     break
    183    endif
    184   endfor
    185 
    186   " Sanity checks: readability and writability
    187   if datadir == ""
    188    echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
    189    return
    190   endif
    191   if filewritable(datadir) != 2
    192    echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
    193    return
    194   endif
    195   let datafile= datadir."/GetLatestVimScripts.dat"
    196   if !filereadable(datafile)
    197    echoerr "Your data file<".datafile."> isn't readable"
    198    return
    199   endif
    200   if !filewritable(datafile)
    201    echoerr "Your data file<".datafile."> isn't writable"
    202    return
    203   endif
    204   " --------------------
    205   " Passed sanity checks
    206   " --------------------
    207 
    208   " don't let any event handlers interfere (like winmanager's, taglist's, etc)
    209   let eikeep  = &ei
    210   let hlskeep = &hls
    211   let acdkeep = &acd
    212   set ei=all hls&vim noacd
    213 
    214   " Edit the datafile (ie. GetLatestVimScripts.dat):
    215   " 1. record current directory (origdir),
    216   " 2. change directory to datadir,
    217   " 3. split window
    218   " 4. edit datafile
    219   let origdir= getcwd()
    220   exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
    221   split
    222   exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
    223   res 1000
    224   let s:downloads = 0
    225   let s:downerrors= 0
    226   let s:message = []
    227 
    228   " Check on dependencies mentioned in plugins
    229   let lastline    = line("$")
    230   let firstdir    = substitute(&rtp,',.*$','','')
    231   let plugins     = split(globpath(firstdir,"plugin/**/*.vim"),'\n')
    232   let plugins     += split(globpath(firstdir,"ftplugin/**/*.vim"),'\n')
    233   let plugins     += split(globpath(firstdir,"AsNeeded/**/*.vim"),'\n')
    234   let plugins     += split(globpath(firstdir,"pack/*/start/*/plugin/**/*.vim"),'\n')
    235   let plugins     += split(globpath(firstdir,"pack/*/opt/*/plugin/**/*.vim"),'\n')
    236   let plugins     += split(globpath(firstdir,"pack/*/start/*/ftplugin/**/*.vim"),'\n')
    237   let plugins     += split(globpath(firstdir,"pack/*/opt/*/ftplugin/**/*.vim"),'\n')
    238   let foundscript = 0
    239 
    240   " this loop updates the GetLatestVimScripts.dat file
    241   " with dependencies explicitly mentioned in the plugins
    242   " via   GetLatestVimScripts: ... lines
    243   " It reads the plugin script at the end of the GetLatestVimScripts.dat
    244   " file, examines it, and then removes it.
    245   for plugin in plugins
    246 
    247    " read plugin in
    248    " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
    249    $
    250    exe "silent r ".fnameescape(plugin)
    251    exe "silent bwipe ".bufnr("#")
    252 
    253    while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
    254     let depscript   = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
    255     let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
    256     let llp1        = lastline+1
    257 
    258     " found a "GetLatestVimScripts: # #" line in the script;
    259     " check if it's already in the datafile by searching backwards from llp1,
    260     " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
    261     " for the script-id with no wrapping allowed.
    262     let curline     = line(".")
    263     let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
    264     exe llp1
    265     let srchline    = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
    266     if srchline == 0
    267      " this second search is taken when, for example, a   0 0 scriptname  is to be skipped over
    268      let srchline= search('\<'.noai_script.'\>','bW')
    269     endif
    270 
    271     if srchline == 0
    272      " found a new script to permanently include in the datafile
    273      let keep_rega   = @a
    274      let @a          = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
    275      echomsg "Appending <".@a."> to ".datafile." for ".depscript
    276      exe lastline."put a"
    277      let @a          = keep_rega
    278      let lastline    = llp1
    279      let curline     = curline     + 1
    280      let foundscript = foundscript + 1
    281     endif
    282 
    283     let curline = curline + 1
    284     exe curline
    285    endwhile
    286 
    287    " llp1: last line plus one
    288    let llp1= lastline + 1
    289    exe "silent! ".llp1.",$d"
    290   endfor
    291 
    292   if foundscript == 0
    293    setlocal nomod
    294   endif
    295 
    296   " --------------------------------------------------------------------
    297   " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
    298   " --------------------------------------------------------------------
    299   setlocal lz
    300   1
    301   /^-----/,$g/^\s*\d/call s:GetOneScript()
    302 
    303   " Final report (an echomsg)
    304   try
    305    silent! ?^-------?
    306   catch /^Vim\%((\a\+)\)\=:E114/
    307    return
    308   endtry
    309   exe "norm! kz\<CR>"
    310   redraw!
    311   if !empty(s:message)
    312    echohl WarningMsg
    313    for mess in s:message
    314     echom mess
    315    endfor
    316    let s:downerrors += len(s:message)
    317   endif
    318   let s:msg = ""
    319   if s:downloads == 1
    320   let s:msg = "Downloaded one updated script to <".datadir.">"
    321   elseif s:downloads > 1
    322    let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
    323   else
    324    let s:msg= empty(s:message) ? "Everything was already current" : "There were some errors"
    325   endif
    326   if s:downerrors > 0
    327    let s:msg= s:msg." (".s:downerrors." downloading errors)"
    328   endif
    329   echomsg s:msg
    330   " save the file
    331   if &mod
    332    silent! w!
    333   endif
    334   q!
    335 
    336   " restore events and current directory
    337   exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
    338   let &ei  = eikeep
    339   let &hls = hlskeep
    340   let &acd = acdkeep
    341   setlocal nolz
    342 endfun
    343 
    344 " ---------------------------------------------------------------------
    345 "  GetOneScript: (Get Latest Vim script) this function operates {{{1
    346 "    on the current line, interpreting two numbers and text as
    347 "    ScriptID, SourceID, and Filename.
    348 "    It downloads any scripts that have newer versions from vim.sourceforge.net.
    349 fun! s:GetOneScript(...)
    350  " set options to allow progress to be shown on screen
    351   let rega= @a
    352   let t_ti= &t_ti
    353   let t_te= &t_te
    354   let rs  = &rs
    355   let ssl = &ssl
    356 
    357   set t_ti= t_te= nors
    358   " avoid issues with shellescape() on Windows
    359   if s:is_windows && &shell =~? '\<cmd\>'
    360     set noshellslash
    361   endif
    362 
    363   " restore valures afterwards
    364   defer execute("let @a = rega | let &t_ti = t_ti | let &t_te = t_te | let &rs = rs | let &ssl = ssl")
    365 
    366  " put current line on top-of-screen and interpret it into
    367  " a      script identifier  : used to obtain webpage
    368  "        source identifier : used to identify current version
    369  " and an associated comment: used to report on what's being considered
    370   if a:0 >= 3
    371    let scriptid = a:1
    372    let srcid    = a:2
    373    let fname    = a:3
    374    let cmmnt    = ""
    375   else
    376    let curline  = getline(".")
    377    if curline =~ '^\s*#'
    378     return
    379    endif
    380    let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
    381    try
    382     let scriptid = substitute(curline,parsepat,'\1','e')
    383    catch /^Vim\%((\a\+)\)\=:E486/
    384     let scriptid= 0
    385    endtry
    386    try
    387     let srcid    = substitute(curline,parsepat,'\2','e')
    388    catch /^Vim\%((\a\+)\)\=:E486/
    389     let srcid= 0
    390    endtry
    391    try
    392     let fname= substitute(curline,parsepat,'\3','e')
    393    catch /^Vim\%((\a\+)\)\=:E486/
    394     let fname= ""
    395    endtry
    396    try
    397     let cmmnt= substitute(curline,parsepat,'\4','e')
    398    catch /^Vim\%((\a\+)\)\=:E486/
    399     let cmmnt= ""
    400    endtry
    401   endif
    402 
    403   " plugin author protection from downloading his/her own scripts atop their latest work
    404   " When looking for :AutoInstall: lines, skip scripts that have   0 0 scriptname
    405   if scriptid == 0 || srcid == 0
    406    return
    407   endif
    408 
    409   let doautoinstall= 0
    410   if fname =~ ":AutoInstall:"
    411    let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
    412    if s:autoinstall != ""
    413     let doautoinstall = g:GetLatestVimScripts_allowautoinstall
    414    endif
    415   else
    416    let aicmmnt= fname
    417   endif
    418 
    419   exe "norm z\<CR>"
    420   redraw!
    421   echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
    422 
    423   " grab a copy of the plugin's vim.sourceforge.net webpage
    424   let scriptaddr = g:GetLatestVimScripts_scriptaddr.scriptid
    425   let tmpfile    = tempname()
    426   let v:errmsg   = ""
    427 
    428   " Check if URLs are reachable
    429   if !CheckVimScriptURL(scriptid, srcid)
    430    return
    431   endif
    432 
    433   " make up to three tries at downloading the description
    434   let itry= 1
    435   while itry <= 3
    436    if has("win32") || has("win16") || has("win95")
    437     new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile,1).' '.shellescape(scriptaddr,1)|bw!
    438    else
    439     exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile,1)." ".shellescape(scriptaddr,1)
    440    endif
    441    if itry == 1
    442     exe "silent vsplit ".fnameescape(tmpfile)
    443    else
    444     silent! e %
    445    endif
    446    setlocal bh=wipe
    447   
    448    " find the latest source-id in the plugin's webpage
    449    silent! 1
    450    let findpkg= search('Click on the package to download','W')
    451    if findpkg > 0
    452     break
    453    endif
    454    let itry= itry + 1
    455   endwhile
    456 
    457   " testing: did finding "Click on the package..." fail?
    458   if findpkg == 0 || itry >= 4
    459    silent q!
    460    call delete(tmpfile)
    461   " restore options
    462    let &t_ti        = t_ti
    463    let &t_te        = t_te
    464    let &rs          = rs
    465    let s:downerrors = s:downerrors + 1
    466    echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
    467    return
    468   endif
    469 
    470   let findsrcid= search('src_id=','W')
    471   if findsrcid == 0
    472    silent q!
    473    call delete(tmpfile)
    474   " restore options
    475    let &t_ti        = t_ti
    476    let &t_te        = t_te
    477    let &rs          = rs
    478    let s:downerrors = s:downerrors + 1
    479    echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
    480    return
    481   endif
    482 
    483   let srcidpat   = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
    484   let latestsrcid= substitute(getline("."),srcidpat,'\1','')
    485   let sname      = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
    486   silent q!
    487   call delete(tmpfile)
    488 
    489   " convert the strings-of-numbers into numbers
    490   let srcid       = srcid       + 0
    491   let latestsrcid = latestsrcid + 0
    492 
    493   " has the plugin's most-recent srcid increased, which indicates that it has been updated
    494   if latestsrcid > srcid
    495 
    496    let s:downloads= s:downloads + 1
    497    if sname == bufname("%")
    498     " GetLatestVimScript has to be careful about downloading itself
    499     let sname= "NEW_".sname
    500    endif
    501 
    502    " -----------------------------------------------------------------------------
    503    " the plugin has been updated since we last obtained it, so download a new copy
    504    " -----------------------------------------------------------------------------
    505    echomsg ".downloading new <".sname.">"
    506    if has("win32") || has("win16") || has("win95")
    507     new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname,1)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid,1)|bw!
    508    else
    509     exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname,1)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid,1)
    510    endif
    511 
    512    " --------------------------------------------------------------------------
    513    " AutoInstall: only if doautoinstall has been requested by the plugin itself
    514    " --------------------------------------------------------------------------
    515    if doautoinstall
    516     if filereadable(sname)
    517      exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname,1)." ".shellescape(s:autoinstall,1)
    518      let curdir    = fnameescape(substitute(getcwd(),'\','/','ge'))
    519      let installdir= curdir."/Installed"
    520      if !isdirectory(installdir)
    521       call mkdir(installdir)
    522      endif
    523      exe "cd ".fnameescape(s:autoinstall)
    524 
    525      " determine target directory for moves
    526      let firstdir= substitute(&rtp,',.*$','','')
    527      let pname   = substitute(sname,'\..*','.vim','')
    528      if filereadable(firstdir.'/AsNeeded/'.pname)
    529       let tgtdir= "AsNeeded"
    530      else
    531       let tgtdir= "plugin"
    532      endif
    533 
    534      " decompress
    535      if sname =~ '\.bz2$'
    536       exe "sil !".g:GetLatestVimScripts_bunzip2." ".shellescape(sname,1)
    537       let sname= substitute(sname,'\.bz2$','','')
    538      elseif sname =~ '\.bz3$'
    539       exe "sil !".g:GetLatestVimScripts_bunzip3." ".shellescape(sname,1)
    540       let sname= substitute(sname,'\.bz3$','','')
    541      elseif sname =~ '\.gz$'
    542       exe "sil !".g:GetLatestVimScripts_gunzip." ".shellescape(sname,1)
    543       let sname= substitute(sname,'\.gz$','','')
    544      elseif sname =~ '\.xz$'
    545       exe "sil !".g:GetLatestVimScripts_unxz." ".shellescape(sname,1)
    546       let sname= substitute(sname,'\.xz$','','')
    547      else
    548      endif
    549 
    550      " distribute archive(.zip, .tar, .vba, .vmb, ...) contents
    551      if sname =~ '\.zip$'
    552       exe "silent !".g:GetLatestVimScripts_unzip." -o ".shellescape(sname,1)
    553      elseif sname =~ '\.tar$'
    554       exe "silent !tar -xvf ".shellescape(sname,1)
    555      elseif sname =~ '\.tgz$'
    556       exe "silent !tar -zxvf ".shellescape(sname,1)
    557      elseif sname =~ '\.taz$'
    558       exe "silent !tar -Zxvf ".shellescape(sname,1)
    559      elseif sname =~ '\.tbz$'
    560       exe "silent !tar -jxvf ".shellescape(sname,1)
    561      elseif sname =~ '\.txz$'
    562       exe "silent !tar -Jxvf ".shellescape(sname,1)
    563      elseif sname =~ '\.vba$\|\.vmb$'
    564       silent 1split
    565       if exists("g:vimball_home")
    566        let oldvimballhome= g:vimball_home
    567       endif
    568       let g:vimball_home= s:autoinstall
    569       exe "silent e ".fnameescape(sname)
    570       silent so %
    571       silent q
    572       if exists("oldvimballhome")
    573        let g:vimball_home= oldvimballhome
    574       else
    575        unlet g:vimball_home
    576       endif
    577      endif
    578 
    579      " ---------------------------------------------
    580      " move plugin to plugin/ or AsNeeded/ directory
    581      " ---------------------------------------------
    582      if sname =~ '.vim$'
    583       exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname,1)." ".tgtdir
    584      else
    585       exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname,1)." ".installdir
    586      endif
    587      if tgtdir != "plugin"
    588       exe "silent !".g:GetLatestVimScripts_mv." ".shellescape("plugin/".pname,1)." ".tgtdir
    589      endif
    590 
    591      " helptags step
    592      let docdir= substitute(&rtp,',.*','','e')."/doc"
    593      exe "helptags ".fnameescape(docdir)
    594      exe "cd ".fnameescape(curdir)
    595     endif
    596     if fname !~ ':AutoInstall:'
    597      let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
    598     else
    599      let modline=scriptid." ".latestsrcid." ".fname.cmmnt
    600     endif
    601    else
    602     let modline=scriptid." ".latestsrcid." ".fname.cmmnt
    603    endif
    604 
    605    " update the data in the <GetLatestVimScripts.dat> file
    606    call setline(line("."),modline)
    607   endif
    608 endfun
    609 
    610 " CheckVimScriptURL: Check Network Connection {{{1
    611 " Check status code of scriptaddr and downloadaddr
    612 " return v:true if the script is downloadable or v:false in case of errors
    613 fun CheckVimScriptURL(script_id, src_id)
    614   " doesn't work with powershell
    615   if !executable('curl') || &shell =~? 'pwsh\|powershell'
    616     return v:true
    617   endif
    618   let output = has("win32") ? ' -o NUL ' : ' -o /dev/null '
    619 
    620   let temp = tempname()
    621   defer delete(temp)
    622   let script_url = g:GetLatestVimScripts_scriptaddr . a:script_id
    623   let download_url = g:GetLatestVimScripts_downloadaddr . a:src_id
    624 
    625   let script_cmd = 'curl -s -I -w "%{http_code}"' . output . shellescape(script_url) . ' >' . shellescape(temp)
    626   call system(script_cmd)
    627   let script_status = readfile(temp, 'b')[0]
    628 
    629   let download_cmd = 'curl -s -I -w "%{http_code}"' . output . shellescape(download_url) . ' >' . shellescape(temp)
    630   call system(download_cmd)
    631   let download_status = readfile(temp, 'b')[0]
    632 
    633   if script_status !=# '200'
    634     let s:message += [ printf('Error: Failed to reach script: %s', a:script_id) ]
    635     return v:false
    636   endif
    637 
    638   if download_status !=# '200'
    639     let s:message += [ printf('Error: Failed to download script %s', a:script_id) ]
    640     return v:false
    641   endif
    642   return v:true
    643 endfun
    644 
    645 " ---------------------------------------------------------------------
    646 " Restore Options: {{{1
    647 let &cpo= s:keepcpo
    648 unlet s:keepcpo
    649 
    650 " ---------------------------------------------------------------------
    651 "  Modelines: {{{1
    652 " vim: ts=8 sts=2 fdm=marker nowrap