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