blob: 148e45bcba6873e9bb23f7ad1bf8dbcc61b89e71 [file] [log] [blame]
Bram Moolenaar60a795a2005-09-16 21:55:43 +00001" zip.vim: Handles browsing zipfiles
Damien2cad9412024-07-24 20:07:00 +02002" AUTOLOAD PORTION
Damienf0e9b722024-08-05 20:21:18 +02003" Date: Aug 05, 2024
Christian Brabandta336d8f2024-08-05 21:26:46 +02004" Version: 34
Christian Brabandtf9ca1392024-02-19 20:37:11 +01005" Maintainer: This runtime file is looking for a new maintainer.
6" Former Maintainer: Charles E Campbell
Christian Brabandt1c673422024-06-15 14:49:24 +02007" Last Change:
Damien2cad9412024-07-24 20:07:00 +02008" 2024 Jun 16 by Vim Project: handle whitespace on Windows properly (#14998)
9" 2024 Jul 23 by Vim Project: fix 'x' command
10" 2024 Jul 24 by Vim Project: use delete() function
Damienf0e9b722024-08-05 20:21:18 +020011" 2024 Jul 30 by Vim Project: fix opening remote zipfile
zeertzjqc5bdd662024-08-04 18:35:50 +020012" 2024 Aug 04 by Vim Project: escape '[' in name of file to be extracted
Damienf0e9b722024-08-05 20:21:18 +020013" 2024 Aug 05 by Vim Project: workaround for the FreeBSD's unzip
Christian Brabandta63f66e2024-08-05 20:47:34 +020014" 2024 Aug 05 by Vim Project: clean-up and make it work with shellslash on Windows
Bram Moolenaar9964e462007-05-05 17:54:07 +000015" License: Vim License (see vim's :help license)
Christian Brabandt1c673422024-06-15 14:49:24 +020016" Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1
17" Permission is hereby granted to use and distribute this code,
18" with or without modifications, provided that this copyright
19" notice is copied with it. Like anything else that's free,
20" zip.vim and zipPlugin.vim are provided *as is* and comes with
21" no warranty of any kind, either expressed or implied. By using
22" this plugin, you agree that in no event will the copyright
23" holder be liable for any damages resulting from the use
24" of this software.
Bram Moolenaar60a795a2005-09-16 21:55:43 +000025
26" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000027" Load Once: {{{1
Bram Moolenaar00a927d2010-05-14 23:24:24 +020028if &cp || exists("g:loaded_zip")
Bram Moolenaar60a795a2005-09-16 21:55:43 +000029 finish
30endif
Christian Brabandta336d8f2024-08-05 21:26:46 +020031let g:loaded_zip= "v34"
Bram Moolenaar00a927d2010-05-14 23:24:24 +020032let s:keepcpo= &cpo
33set cpo&vim
Bram Moolenaar60a795a2005-09-16 21:55:43 +000034
Bram Moolenaardb552d602006-03-23 22:59:57 +000035let s:zipfile_escape = ' ?&;\'
Bram Moolenaar9964e462007-05-05 17:54:07 +000036let s:ERROR = 2
37let s:WARNING = 1
38let s:NOTE = 0
39
40" ---------------------------------------------------------------------
41" Global Values: {{{1
42if !exists("g:zip_shq")
Bram Moolenaar446cb832008-06-24 21:56:24 +000043 if &shq != ""
44 let g:zip_shq= &shq
45 elseif has("unix")
Bram Moolenaar9964e462007-05-05 17:54:07 +000046 let g:zip_shq= "'"
47 else
48 let g:zip_shq= '"'
49 endif
50endif
Bram Moolenaarccc18222007-05-10 18:25:20 +000051if !exists("g:zip_zipcmd")
52 let g:zip_zipcmd= "zip"
53endif
54if !exists("g:zip_unzipcmd")
55 let g:zip_unzipcmd= "unzip"
56endif
Bram Moolenaard0796902016-09-16 20:02:31 +020057if !exists("g:zip_extractcmd")
58 let g:zip_extractcmd= g:zip_unzipcmd
59endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +000060
Christian Brabandt8d529262024-08-06 18:35:00 +020061" ---------------------------------------------------------------------
62" required early
63" s:Mess: {{{2
64fun! s:Mess(group, msg)
65 redraw!
66 exe "echohl " . a:group
67 echomsg a:msg
68 echohl Normal
69endfun
70
71if v:version < 900
72 call s:Mess('WarningMsg', "***warning*** this version of zip needs vim 9.0 or later")
73 finish
74endif
D. Ben Knoblecd8a3ea2023-11-04 05:11:17 -040075if !dist#vim#IsSafeExecutable('zip', g:zip_unzipcmd)
Christian Brabandt8d529262024-08-06 18:35:00 +020076 call s:Mess('Error', "Warning: NOT executing " .. g:zip_unzipcmd .. " from current directory!")
Christian Brabandt816fbcc2023-08-31 23:52:30 +020077 finish
78endif
Anton Sharonov67c951d2023-09-05 21:03:27 +020079
Bram Moolenaar60a795a2005-09-16 21:55:43 +000080" ----------------
81" Functions: {{{1
82" ----------------
83
84" ---------------------------------------------------------------------
85" zip#Browse: {{{2
86fun! zip#Browse(zipfile)
Damienc4be0662024-07-30 19:14:35 +020087 " sanity check: ensure that the zipfile has "PK" as its first two letters
88 " (zip files have a leading PK as a "magic cookie")
89 if filereadable(a:zipfile) && readblob(a:zipfile, 0, 2) != 0z50.4B
90 exe "noswapfile noautocmd e " .. fnameescape(a:zipfile)
Bram Moolenaar94f76b72013-07-04 22:50:40 +020091 return
Bram Moolenaar94f76b72013-07-04 22:50:40 +020092 endif
93
Christian Brabandt19636be2024-08-05 21:00:07 +020094 let dict = s:SetSaneOpts()
Christian Brabandtafea6b92024-08-06 18:50:59 +020095 defer s:RestoreOpts(dict)
Bram Moolenaar60a795a2005-09-16 21:55:43 +000096
97 " sanity checks
Bram Moolenaarccc18222007-05-10 18:25:20 +000098 if !executable(g:zip_unzipcmd)
Christian Brabandt8d529262024-08-06 18:35:00 +020099 call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000100 return
101 endif
102 if !filereadable(a:zipfile)
Bram Moolenaara5792f52005-11-23 21:25:05 +0000103 if a:zipfile !~# '^\a\+://'
Bram Moolenaar8024f932020-01-14 19:29:13 +0100104 " if it's an url, don't complain, let url-handlers such as vim do its thing
Christian Brabandt8d529262024-08-06 18:35:00 +0200105 call s:Mess('Error', "***error*** (zip#Browse) File not readable <".a:zipfile.">")
Bram Moolenaara5792f52005-11-23 21:25:05 +0000106 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000107 return
108 endif
109 if &ma != 1
110 set ma
111 endif
Bram Moolenaarccc18222007-05-10 18:25:20 +0000112 let b:zipfile= a:zipfile
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000113
114 setlocal noswapfile
115 setlocal buftype=nofile
116 setlocal bufhidden=hide
117 setlocal nobuflisted
118 setlocal nowrap
Bram Moolenaar519cc552021-11-16 19:18:26 +0000119
120 " Oct 12, 2021: need to re-use Bram's syntax/tar.vim.
121 " Setting the filetype to zip doesn't do anything (currently),
122 " but it is perhaps less confusing to curious perusers who do
123 " a :echo &ft
124 setf zip
125 run! syntax/tar.vim
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000126
127 " give header
Bram Moolenaar251e1912011-06-19 05:09:16 +0200128 call append(0, ['" zip.vim version '.g:loaded_zip,
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100129 \ '" Browsing zipfile '.a:zipfile,
130 \ '" Select a file with cursor and press ENTER'])
Bram Moolenaar251e1912011-06-19 05:09:16 +0200131 keepj $
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000132
Damienf0e9b722024-08-05 20:21:18 +0200133 exe $"keepj sil r! {g:zip_unzipcmd} -Z1 -- {s:Escape(a:zipfile, 1)}"
Bram Moolenaard68071d2006-05-02 22:08:30 +0000134 if v:shell_error != 0
Christian Brabandt8d529262024-08-06 18:35:00 +0200135 call s:Mess('WarningMsg', "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200136 keepj sil! %d
Bram Moolenaard68071d2006-05-02 22:08:30 +0000137 let eikeep= &ei
138 set ei=BufReadCmd,FileReadCmd
Bram Moolenaar251e1912011-06-19 05:09:16 +0200139 exe "keepj r ".fnameescape(a:zipfile)
Bram Moolenaard68071d2006-05-02 22:08:30 +0000140 let &ei= eikeep
Bram Moolenaar251e1912011-06-19 05:09:16 +0200141 keepj 1d
Bram Moolenaard68071d2006-05-02 22:08:30 +0000142 return
143 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000144
Bram Moolenaard0796902016-09-16 20:02:31 +0200145 " Maps associated with zip plugin
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000146 setlocal noma nomod ro
Bram Moolenaar29634562020-01-09 21:46:04 +0100147 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr>
148 noremap <silent> <buffer> x :call zip#Extract()<cr>
149 if &mouse != ""
150 noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>ZipBrowseSelect()<cr>
151 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000152
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000153endfun
154
155" ---------------------------------------------------------------------
156" ZipBrowseSelect: {{{2
157fun! s:ZipBrowseSelect()
Christian Brabandt19636be2024-08-05 21:00:07 +0200158 let dict = s:SetSaneOpts()
Christian Brabandtafea6b92024-08-06 18:50:59 +0200159 defer s:RestoreOpts(dict)
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000160 let fname= getline(".")
Bram Moolenaar71badf92023-04-22 22:40:14 +0100161 if !exists("b:zipfile")
Bram Moolenaar71badf92023-04-22 22:40:14 +0100162 return
163 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000164
165 " sanity check
166 if fname =~ '^"'
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000167 return
168 endif
169 if fname =~ '/$'
Christian Brabandt8d529262024-08-06 18:35:00 +0200170 call s:Mess('Error', "***error*** (zip#Browse) Please specify a file, not a directory")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000171 return
172 endif
173
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000174 " get zipfile to the new-window
Bram Moolenaarccc18222007-05-10 18:25:20 +0000175 let zipfile = b:zipfile
Bram Moolenaar29634562020-01-09 21:46:04 +0100176 let curfile = expand("%")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000177
Bram Moolenaar29634562020-01-09 21:46:04 +0100178 noswapfile new
Bram Moolenaar446cb832008-06-24 21:56:24 +0000179 if !exists("g:zip_nomax") || g:zip_nomax == 0
180 wincmd _
181 endif
Bram Moolenaara5792f52005-11-23 21:25:05 +0000182 let s:zipfile_{winnr()}= curfile
Bram Moolenaar519cc552021-11-16 19:18:26 +0000183 exe "noswapfile e ".fnameescape("zipfile://".zipfile.'::'.fname)
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000184 filetype detect
185
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000186endfun
187
188" ---------------------------------------------------------------------
189" zip#Read: {{{2
190fun! zip#Read(fname,mode)
Christian Brabandt19636be2024-08-05 21:00:07 +0200191 let dict = s:SetSaneOpts()
Christian Brabandtafea6b92024-08-06 18:50:59 +0200192 defer s:RestoreOpts(dict)
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000193
Bram Moolenaard68071d2006-05-02 22:08:30 +0000194 if has("unix")
Bram Moolenaar519cc552021-11-16 19:18:26 +0000195 let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','')
196 let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','')
Bram Moolenaard68071d2006-05-02 22:08:30 +0000197 else
Bram Moolenaar519cc552021-11-16 19:18:26 +0000198 let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','')
199 let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','')
Bram Moolenaard68071d2006-05-02 22:08:30 +0000200 endif
zeertzjqc5bdd662024-08-04 18:35:50 +0200201 let fname = substitute(fname, '[', '[[]', 'g')
Bram Moolenaard0796902016-09-16 20:02:31 +0200202 " sanity check
203 if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','',''))
Christian Brabandt8d529262024-08-06 18:35:00 +0200204 call s:Mess('Error', "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program")
Bram Moolenaard0796902016-09-16 20:02:31 +0200205 return
206 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000207
Bram Moolenaarff034192013-04-24 18:51:19 +0200208 " the following code does much the same thing as
zeertzjqc5bdd662024-08-04 18:35:50 +0200209 " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fname,1)
Bram Moolenaar519cc552021-11-16 19:18:26 +0000210 " but allows zipfile://... entries in quickfix lists
Bram Moolenaarff034192013-04-24 18:51:19 +0200211 let temp = tempname()
212 let fn = expand('%:p')
Damienf0e9b722024-08-05 20:21:18 +0200213 exe "sil !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fname,1).' > '.temp
Bram Moolenaarff034192013-04-24 18:51:19 +0200214 sil exe 'keepalt file '.temp
215 sil keepj e!
216 sil exe 'keepalt file '.fnameescape(fn)
217 call delete(temp)
218
Bram Moolenaar251e1912011-06-19 05:09:16 +0200219 filetype detect
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000220
221 " cleanup
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000222 set nomod
223
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000224endfun
225
226" ---------------------------------------------------------------------
227" zip#Write: {{{2
228fun! zip#Write(fname)
Christian Brabandt19636be2024-08-05 21:00:07 +0200229 let dict = s:SetSaneOpts()
Christian Brabandtafea6b92024-08-06 18:50:59 +0200230 defer s:RestoreOpts(dict)
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000231
232 " sanity checks
Bram Moolenaard0796902016-09-16 20:02:31 +0200233 if !executable(substitute(g:zip_zipcmd,'\s\+.*$','',''))
Christian Brabandt8d529262024-08-06 18:35:00 +0200234 call s:Mess('Error', "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000235 return
236 endif
237 if !exists("*mkdir")
Christian Brabandt8d529262024-08-06 18:35:00 +0200238 call s:Mess('Error', "***error*** (zip#Write) sorry, mkdir() doesn't work on your system")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000239 return
240 endif
241
242 let curdir= getcwd()
243 let tmpdir= tempname()
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000244 if tmpdir =~ '\.'
245 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
246 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000247 call mkdir(tmpdir,"p")
248
249 " attempt to change to the indicated directory
Bram Moolenaar9964e462007-05-05 17:54:07 +0000250 if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000251 return
Bram Moolenaar9964e462007-05-05 17:54:07 +0000252 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000253
254 " place temporary files under .../_ZIPVIM_/
255 if isdirectory("_ZIPVIM_")
Damien2cad9412024-07-24 20:07:00 +0200256 call delete("_ZIPVIM_", "rf")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000257 endif
258 call mkdir("_ZIPVIM_")
259 cd _ZIPVIM_
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000260
Bram Moolenaard68071d2006-05-02 22:08:30 +0000261 if has("unix")
Bram Moolenaar519cc552021-11-16 19:18:26 +0000262 let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','')
263 let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','')
Bram Moolenaard68071d2006-05-02 22:08:30 +0000264 else
Bram Moolenaar519cc552021-11-16 19:18:26 +0000265 let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','')
266 let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','')
Bram Moolenaard68071d2006-05-02 22:08:30 +0000267 endif
Bram Moolenaarc7486e02005-12-29 22:48:26 +0000268
269 if fname =~ '/'
270 let dirpath = substitute(fname,'/[^/]\+$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +0200271 if has("win32unix") && executable("cygpath")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000272 let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e')
Bram Moolenaarc7486e02005-12-29 22:48:26 +0000273 endif
274 call mkdir(dirpath,"p")
275 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000276 if zipfile !~ '/'
277 let zipfile= curdir.'/'.zipfile
278 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000279
Bram Moolenaarc236c162008-07-13 17:41:49 +0000280 exe "w! ".fnameescape(fname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200281 if has("win32unix") && executable("cygpath")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000282 let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e')
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000283 endif
284
Bram Moolenaar9964e462007-05-05 17:54:07 +0000285 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
286 let fname = substitute(fname, '[', '[[]', 'g')
287 endif
288
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000289 call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0))
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000290 if v:shell_error != 0
Christian Brabandt8d529262024-08-06 18:35:00 +0200291 call s:Mess('Error', "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname)
Bram Moolenaara5792f52005-11-23 21:25:05 +0000292
293 elseif s:zipfile_{winnr()} =~ '^\a\+://'
294 " support writing zipfiles across a network
295 let netzipfile= s:zipfile_{winnr()}
Bram Moolenaara5792f52005-11-23 21:25:05 +0000296 1split|enew
297 let binkeep= &binary
298 let eikeep = &ei
299 set binary ei=all
Bram Moolenaar29634562020-01-09 21:46:04 +0100300 exe "noswapfile e! ".fnameescape(zipfile)
Bram Moolenaara5792f52005-11-23 21:25:05 +0000301 call netrw#NetWrite(netzipfile)
302 let &ei = eikeep
303 let &binary = binkeep
304 q!
305 unlet s:zipfile_{winnr()}
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000306 endif
Damien2cad9412024-07-24 20:07:00 +0200307
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000308 " cleanup and restore current directory
309 cd ..
Damien2cad9412024-07-24 20:07:00 +0200310 call delete("_ZIPVIM_", "rf")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000311 call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!")
Damien2cad9412024-07-24 20:07:00 +0200312 call delete(tmpdir, "rf")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000313 setlocal nomod
314
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000315endfun
316
317" ---------------------------------------------------------------------
Bram Moolenaard0796902016-09-16 20:02:31 +0200318" zip#Extract: extract a file from a zip archive {{{2
319fun! zip#Extract()
Bram Moolenaard0796902016-09-16 20:02:31 +0200320
Christian Brabandt19636be2024-08-05 21:00:07 +0200321 let dict = s:SetSaneOpts()
Christian Brabandtafea6b92024-08-06 18:50:59 +0200322 defer s:RestoreOpts(dict)
Bram Moolenaard0796902016-09-16 20:02:31 +0200323 let fname= getline(".")
Bram Moolenaard0796902016-09-16 20:02:31 +0200324
325 " sanity check
326 if fname =~ '^"'
Bram Moolenaard0796902016-09-16 20:02:31 +0200327 return
328 endif
329 if fname =~ '/$'
Christian Brabandt8d529262024-08-06 18:35:00 +0200330 call s:Mess('Error', "***error*** (zip#Extract) Please specify a file, not a directory")
Bram Moolenaard0796902016-09-16 20:02:31 +0200331 return
332 endif
333
334 " extract the file mentioned under the cursor
Damien38ce71c2024-07-23 19:56:54 +0200335 call system($"{g:zip_extractcmd} {shellescape(b:zipfile)} {shellescape(fname)}")
Bram Moolenaard0796902016-09-16 20:02:31 +0200336 if v:shell_error != 0
Christian Brabandt8d529262024-08-06 18:35:00 +0200337 call s:Mess('Error', "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!")
Bram Moolenaard0796902016-09-16 20:02:31 +0200338 elseif !filereadable(fname)
Christian Brabandt8d529262024-08-06 18:35:00 +0200339 call s:Mess('Error', "***error*** attempted to extract ".fname." but it doesn't appear to be present!")
Bram Moolenaard0796902016-09-16 20:02:31 +0200340 else
Christian Brabandt120c0dd2024-08-05 20:51:47 +0200341 echomsg "***note*** successfully extracted ".fname
Bram Moolenaard0796902016-09-16 20:02:31 +0200342 endif
343
Bram Moolenaard0796902016-09-16 20:02:31 +0200344endfun
345
346" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +0000347" s:Escape: {{{2
348fun! s:Escape(fname,isfilt)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000349 if exists("*shellescape")
350 if a:isfilt
351 let qnameq= shellescape(a:fname,1)
352 else
353 let qnameq= shellescape(a:fname)
354 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000355 else
356 let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq
357 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000358 return qnameq
Bram Moolenaar9964e462007-05-05 17:54:07 +0000359endfun
360
361" ---------------------------------------------------------------------
Christian Brabandt19636be2024-08-05 21:00:07 +0200362" s:ChgDir: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363fun! s:ChgDir(newdir,errlvl,errmsg)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000364 try
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000365 exe "cd ".fnameescape(a:newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000366 catch /^Vim\%((\a\+)\)\=:E344/
367 redraw!
368 if a:errlvl == s:NOTE
Christian Brabandt120c0dd2024-08-05 20:51:47 +0200369 echomsg "***note*** ".a:errmsg
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370 elseif a:errlvl == s:WARNING
Christian Brabandt8d529262024-08-06 18:35:00 +0200371 call s:Mess("WarningMsg", "***warning*** ".a:errmsg)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 elseif a:errlvl == s:ERROR
Christian Brabandt8d529262024-08-06 18:35:00 +0200373 call s:Mess("Error", "***error*** ".a:errmsg)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000375 return 1
376 endtry
377
Bram Moolenaar9964e462007-05-05 17:54:07 +0000378 return 0
379endfun
380
Christian Brabandt19636be2024-08-05 21:00:07 +0200381" ---------------------------------------------------------------------
382" s:SetSaneOpts: {{{2
383fun! s:SetSaneOpts()
384 let dict = {}
385 let dict.report = &report
386 let dict.shellslash = &shellslash
387
388 let &report = 10
389 let &shellslash = 0
390
391 return dict
392endfun
393
394" ---------------------------------------------------------------------
395" s:RestoreOpts: {{{2
396fun! s:RestoreOpts(dict)
397 for [key, val] in items(a:dict)
398 exe $"let &{key} = {val}"
399 endfor
400endfun
401
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000402" ------------------------------------------------------------------------
403" Modelines And Restoration: {{{1
404let &cpo= s:keepcpo
405unlet s:keepcpo
Bram Moolenaarccc18222007-05-10 18:25:20 +0000406" vim:ts=8 fdm=marker