Mercurial > vim
annotate runtime/autoload/zip.vim @ 12380:811338160414
Added tag v8.0.1069 for changeset 25f854eefe98df7140c6df90f6abb60dca6b7685
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 07 Sep 2017 20:30:04 +0200 |
parents | 8a1481e59d64 |
children | 1a951a4beee3 |
rev | line source |
---|---|
530 | 1 " zip.vim: Handles browsing zipfiles |
2 " AUTOLOAD PORTION | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
3 " Date: Sep 13, 2016 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
4 " Version: 28 |
4339 | 5 " Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> |
1121 | 6 " License: Vim License (see vim's :help license) |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
7 " Copyright: Copyright (C) 2005-2013 Charles E. Campbell {{{1 |
530 | 8 " Permission is hereby granted to use and distribute this code, |
9 " with or without modifications, provided that this copyright | |
10 " notice is copied with it. Like anything else that's free, | |
1621 | 11 " zip.vim and zipPlugin.vim are provided *as is* and comes with |
12 " no warranty of any kind, either expressed or implied. By using | |
13 " this plugin, you agree that in no event will the copyright | |
530 | 14 " holder be liable for any damages resulting from the use |
15 " of this software. | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
16 "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
530 | 17 |
18 " --------------------------------------------------------------------- | |
1121 | 19 " Load Once: {{{1 |
2152 | 20 if &cp || exists("g:loaded_zip") |
21 finish | |
22 endif | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
23 let g:loaded_zip= "v28" |
2152 | 24 if v:version < 702 |
25 echohl WarningMsg | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
26 echo "***warning*** this version of zip needs vim 7.2 or later" |
2152 | 27 echohl Normal |
28 finish | |
29 endif | |
530 | 30 let s:keepcpo= &cpo |
31 set cpo&vim | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
32 "DechoTabOn |
530 | 33 |
798 | 34 let s:zipfile_escape = ' ?&;\' |
1121 | 35 let s:ERROR = 2 |
36 let s:WARNING = 1 | |
37 let s:NOTE = 0 | |
38 | |
39 " --------------------------------------------------------------------- | |
40 " Global Values: {{{1 | |
41 if !exists("g:zip_shq") | |
1621 | 42 if &shq != "" |
43 let g:zip_shq= &shq | |
44 elseif has("unix") | |
1121 | 45 let g:zip_shq= "'" |
46 else | |
47 let g:zip_shq= '"' | |
48 endif | |
49 endif | |
1214 | 50 if !exists("g:zip_zipcmd") |
51 let g:zip_zipcmd= "zip" | |
52 endif | |
53 if !exists("g:zip_unzipcmd") | |
54 let g:zip_unzipcmd= "unzip" | |
55 endif | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
56 if !exists("g:zip_extractcmd") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
57 let g:zip_extractcmd= g:zip_unzipcmd |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
58 endif |
530 | 59 |
60 " ---------------- | |
61 " Functions: {{{1 | |
62 " ---------------- | |
63 | |
64 " --------------------------------------------------------------------- | |
65 " zip#Browse: {{{2 | |
66 fun! zip#Browse(zipfile) | |
67 " call Dfunc("zip#Browse(zipfile<".a:zipfile.">)") | |
10228
8a1481e59d64
commit https://github.com/vim/vim/commit/3e496b0ea31996b665824f45664dee1fdd73c4d0
Christian Brabandt <cb@256bit.org>
parents:
10211
diff
changeset
|
68 " sanity check: ensure that the zipfile has "PK" as its first two letters |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
69 " (zipped files have a leading PK as a "magic cookie") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
70 if !filereadable(a:zipfile) || readfile(a:zipfile, "", 1)[0] !~ '^PK' |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
71 exe "noautocmd e ".fnameescape(a:zipfile) |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
72 " call Dret("zip#Browse : not a zipfile<".a:zipfile.">") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
73 return |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
74 " else " Decho |
10228
8a1481e59d64
commit https://github.com/vim/vim/commit/3e496b0ea31996b665824f45664dee1fdd73c4d0
Christian Brabandt <cb@256bit.org>
parents:
10211
diff
changeset
|
75 " call Decho("zip#Browse: a:zipfile<".a:zipfile."> passed PK test - it's a zip file") |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
76 endif |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
77 |
568 | 78 let repkeep= &report |
79 set report=10 | |
530 | 80 |
81 " sanity checks | |
1698 | 82 if !exists("*fnameescape") |
83 if &verbose > 1 | |
84 echoerr "the zip plugin is not available (your vim doens't support fnameescape())" | |
85 endif | |
86 return | |
87 endif | |
1214 | 88 if !executable(g:zip_unzipcmd) |
1121 | 89 redraw! |
530 | 90 echohl Error | echo "***error*** (zip#Browse) unzip not available on your system" |
1121 | 91 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 92 let &report= repkeep |
530 | 93 " call Dret("zip#Browse") |
94 return | |
95 endif | |
96 if !filereadable(a:zipfile) | |
557 | 97 if a:zipfile !~# '^\a\+://' |
10228
8a1481e59d64
commit https://github.com/vim/vim/commit/3e496b0ea31996b665824f45664dee1fdd73c4d0
Christian Brabandt <cb@256bit.org>
parents:
10211
diff
changeset
|
98 " if it's an url, don't complain, let url-handlers such as vim do its thing |
1121 | 99 redraw! |
557 | 100 echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None |
1121 | 101 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 102 endif |
568 | 103 let &report= repkeep |
557 | 104 " call Dret("zip#Browse : file<".a:zipfile."> not readable") |
530 | 105 return |
106 endif | |
798 | 107 " call Decho("passed sanity checks") |
530 | 108 if &ma != 1 |
109 set ma | |
110 endif | |
1214 | 111 let b:zipfile= a:zipfile |
530 | 112 |
113 setlocal noswapfile | |
114 setlocal buftype=nofile | |
115 setlocal bufhidden=hide | |
116 setlocal nobuflisted | |
117 setlocal nowrap | |
118 set ft=tar | |
119 | |
120 " give header | |
2908 | 121 call append(0, ['" zip.vim version '.g:loaded_zip, |
3281 | 122 \ '" Browsing zipfile '.a:zipfile, |
123 \ '" Select a file with cursor and press ENTER']) | |
2908 | 124 keepj $ |
530 | 125 |
1698 | 126 " call Decho("exe silent r! ".g:zip_unzipcmd." -l -- ".s:Escape(a:zipfile,1)) |
3281 | 127 exe "keepj sil! r! ".g:zip_unzipcmd." -Z -1 -- ".s:Escape(a:zipfile,1) |
857 | 128 if v:shell_error != 0 |
1121 | 129 redraw! |
1668 | 130 echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None |
1121 | 131 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
2908 | 132 keepj sil! %d |
857 | 133 let eikeep= &ei |
134 set ei=BufReadCmd,FileReadCmd | |
2908 | 135 exe "keepj r ".fnameescape(a:zipfile) |
857 | 136 let &ei= eikeep |
2908 | 137 keepj 1d |
857 | 138 " call Dret("zip#Browse") |
139 return | |
140 endif | |
530 | 141 |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
142 " Maps associated with zip plugin |
530 | 143 setlocal noma nomod ro |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
144 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr> |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
145 noremap <silent> <buffer> x :call zip#Extract()<cr> |
530 | 146 |
568 | 147 let &report= repkeep |
530 | 148 " call Dret("zip#Browse") |
149 endfun | |
150 | |
151 " --------------------------------------------------------------------- | |
152 " ZipBrowseSelect: {{{2 | |
153 fun! s:ZipBrowseSelect() | |
1214 | 154 " call Dfunc("ZipBrowseSelect() zipfile<".b:zipfile."> curfile<".expand("%").">") |
568 | 155 let repkeep= &report |
156 set report=10 | |
530 | 157 let fname= getline(".") |
158 | |
159 " sanity check | |
160 if fname =~ '^"' | |
568 | 161 let &report= repkeep |
530 | 162 " call Dret("ZipBrowseSelect") |
163 return | |
164 endif | |
165 if fname =~ '/$' | |
1121 | 166 redraw! |
530 | 167 echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None |
1121 | 168 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 169 let &report= repkeep |
530 | 170 " call Dret("ZipBrowseSelect") |
171 return | |
172 endif | |
173 | |
174 " call Decho("fname<".fname.">") | |
175 | |
176 " get zipfile to the new-window | |
1214 | 177 let zipfile = b:zipfile |
819 | 178 let curfile= expand("%") |
798 | 179 " call Decho("zipfile<".zipfile.">") |
180 " call Decho("curfile<".curfile.">") | |
530 | 181 |
182 new | |
1621 | 183 if !exists("g:zip_nomax") || g:zip_nomax == 0 |
184 wincmd _ | |
185 endif | |
557 | 186 let s:zipfile_{winnr()}= curfile |
1668 | 187 " call Decho("exe e ".fnameescape("zipfile:".zipfile.'::'.fname)) |
188 exe "e ".fnameescape("zipfile:".zipfile.'::'.fname) | |
530 | 189 filetype detect |
190 | |
568 | 191 let &report= repkeep |
557 | 192 " call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
530 | 193 endfun |
194 | |
195 " --------------------------------------------------------------------- | |
196 " zip#Read: {{{2 | |
197 fun! zip#Read(fname,mode) | |
198 " call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")") | |
568 | 199 let repkeep= &report |
200 set report=10 | |
201 | |
857 | 202 if has("unix") |
203 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
204 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','') | |
205 else | |
206 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
207 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','') | |
4339 | 208 let fname = substitute(fname, '[', '[[]', 'g') |
857 | 209 endif |
210 " call Decho("zipfile<".zipfile.">") | |
211 " call Decho("fname <".fname.">") | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
212 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
213 if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
214 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
215 echohl Error | echo "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
216 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
217 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
218 " call Dret("zip#Write") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
219 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
220 endif |
530 | 221 |
4339 | 222 " the following code does much the same thing as |
223 " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1) | |
224 " but allows zipfile:... entries in quickfix lists | |
225 let temp = tempname() | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
226 " call Decho("using temp file<".temp.">") |
4339 | 227 let fn = expand('%:p') |
228 exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp | |
229 " call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp) | |
230 sil exe 'keepalt file '.temp | |
231 sil keepj e! | |
232 sil exe 'keepalt file '.fnameescape(fn) | |
233 call delete(temp) | |
234 | |
2908 | 235 filetype detect |
530 | 236 |
237 " cleanup | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
238 " keepj 0d " used to be needed for the ...r! ... method |
530 | 239 set nomod |
240 | |
568 | 241 let &report= repkeep |
530 | 242 " call Dret("zip#Read") |
243 endfun | |
244 | |
245 " --------------------------------------------------------------------- | |
246 " zip#Write: {{{2 | |
247 fun! zip#Write(fname) | |
819 | 248 " call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
568 | 249 let repkeep= &report |
250 set report=10 | |
530 | 251 |
252 " sanity checks | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
253 if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) |
1121 | 254 redraw! |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
255 echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None |
1121 | 256 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 257 let &report= repkeep |
530 | 258 " call Dret("zip#Write") |
259 return | |
260 endif | |
261 if !exists("*mkdir") | |
1121 | 262 redraw! |
530 | 263 echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None |
1121 | 264 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 265 let &report= repkeep |
530 | 266 " call Dret("zip#Write") |
267 return | |
268 endif | |
269 | |
270 let curdir= getcwd() | |
271 let tmpdir= tempname() | |
272 " call Decho("orig tempname<".tmpdir.">") | |
273 if tmpdir =~ '\.' | |
274 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | |
275 endif | |
276 " call Decho("tmpdir<".tmpdir.">") | |
277 call mkdir(tmpdir,"p") | |
278 | |
279 " attempt to change to the indicated directory | |
1121 | 280 if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") |
568 | 281 let &report= repkeep |
530 | 282 " call Dret("zip#Write") |
283 return | |
1121 | 284 endif |
530 | 285 " call Decho("current directory now: ".getcwd()) |
286 | |
287 " place temporary files under .../_ZIPVIM_/ | |
288 if isdirectory("_ZIPVIM_") | |
289 call s:Rmdir("_ZIPVIM_") | |
290 endif | |
291 call mkdir("_ZIPVIM_") | |
292 cd _ZIPVIM_ | |
293 " call Decho("current directory now: ".getcwd()) | |
294 | |
857 | 295 if has("unix") |
296 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
297 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','') | |
298 else | |
299 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
300 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','') | |
301 endif | |
302 " call Decho("zipfile<".zipfile.">") | |
303 " call Decho("fname <".fname.">") | |
623 | 304 |
305 if fname =~ '/' | |
306 let dirpath = substitute(fname,'/[^/]\+$','','e') | |
4339 | 307 if has("win32unix") && executable("cygpath") |
1668 | 308 let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e') |
623 | 309 endif |
819 | 310 " call Decho("mkdir(dirpath<".dirpath.">,p)") |
623 | 311 call mkdir(dirpath,"p") |
312 endif | |
530 | 313 if zipfile !~ '/' |
314 let zipfile= curdir.'/'.zipfile | |
315 endif | |
316 " call Decho("zipfile<".zipfile."> fname<".fname.">") | |
317 | |
1668 | 318 exe "w! ".fnameescape(fname) |
4339 | 319 if has("win32unix") && executable("cygpath") |
1668 | 320 let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e') |
530 | 321 endif |
322 | |
1121 | 323 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
324 let fname = substitute(fname, '[', '[[]', 'g') | |
325 endif | |
326 | |
1698 | 327 " call Decho(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) |
328 call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) | |
530 | 329 if v:shell_error != 0 |
1121 | 330 redraw! |
530 | 331 echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None |
1121 | 332 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 333 |
334 elseif s:zipfile_{winnr()} =~ '^\a\+://' | |
335 " support writing zipfiles across a network | |
336 let netzipfile= s:zipfile_{winnr()} | |
1121 | 337 " call Decho("handle writing <".zipfile."> across network as <".netzipfile.">") |
557 | 338 1split|enew |
339 let binkeep= &binary | |
340 let eikeep = &ei | |
341 set binary ei=all | |
1668 | 342 exe "e! ".fnameescape(zipfile) |
557 | 343 call netrw#NetWrite(netzipfile) |
344 let &ei = eikeep | |
345 let &binary = binkeep | |
346 q! | |
347 unlet s:zipfile_{winnr()} | |
530 | 348 endif |
349 | |
350 " cleanup and restore current directory | |
351 cd .. | |
352 call s:Rmdir("_ZIPVIM_") | |
1121 | 353 call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!") |
354 call s:Rmdir(tmpdir) | |
530 | 355 setlocal nomod |
356 | |
568 | 357 let &report= repkeep |
530 | 358 " call Dret("zip#Write") |
359 endfun | |
360 | |
361 " --------------------------------------------------------------------- | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
362 " zip#Extract: extract a file from a zip archive {{{2 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
363 fun! zip#Extract() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
364 " call Dfunc("zip#Extract()") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
365 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
366 let repkeep= &report |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
367 set report=10 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
368 let fname= getline(".") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
369 " call Decho("fname<".fname.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
370 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
371 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
372 if fname =~ '^"' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
373 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
374 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
375 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
376 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
377 if fname =~ '/$' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
378 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
379 echohl Error | echo "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
380 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
381 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
382 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
383 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
384 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
385 " extract the file mentioned under the cursor |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
386 " call Decho("system(".g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell).")") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
387 call system(g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell)) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
388 " call Decho("zipfile<".b:zipfile.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
389 if v:shell_error != 0 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
390 echohl Error | echo "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
391 elseif !filereadable(fname) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
392 echohl Error | echo "***error*** attempted to extract ".fname." but it doesn't appear to be present!" |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
393 else |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
394 echo "***note*** successfully extracted ".fname |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
395 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
396 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
397 " restore option |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
398 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
399 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
400 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
401 endfun |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
402 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
403 " --------------------------------------------------------------------- |
1668 | 404 " s:Escape: {{{2 |
405 fun! s:Escape(fname,isfilt) | |
406 " call Dfunc("QuoteFileDir(fname<".a:fname."> isfilt=".a:isfilt.")") | |
407 if exists("*shellescape") | |
408 if a:isfilt | |
409 let qnameq= shellescape(a:fname,1) | |
410 else | |
411 let qnameq= shellescape(a:fname) | |
412 endif | |
1621 | 413 else |
414 let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq | |
415 endif | |
416 " call Dret("QuoteFileDir <".qnameq.">") | |
417 return qnameq | |
1121 | 418 endfun |
419 | |
420 " --------------------------------------------------------------------- | |
421 " ChgDir: {{{2 | |
422 fun! s:ChgDir(newdir,errlvl,errmsg) | |
423 " call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl." errmsg<".a:errmsg.">)") | |
424 | |
425 try | |
1698 | 426 exe "cd ".fnameescape(a:newdir) |
1121 | 427 catch /^Vim\%((\a\+)\)\=:E344/ |
428 redraw! | |
429 if a:errlvl == s:NOTE | |
430 echo "***note*** ".a:errmsg | |
431 elseif a:errlvl == s:WARNING | |
432 echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE | |
433 elseif a:errlvl == s:ERROR | |
434 echohl Error | echo "***error*** ".a:errmsg | echohl NONE | |
435 endif | |
436 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
437 " call Dret("ChgDir 1") | |
438 return 1 | |
439 endtry | |
440 | |
441 " call Dret("ChgDir 0") | |
442 return 0 | |
443 endfun | |
444 | |
445 " --------------------------------------------------------------------- | |
1668 | 446 " s:Rmdir: {{{2 |
530 | 447 fun! s:Rmdir(fname) |
448 " call Dfunc("Rmdir(fname<".a:fname.">)") | |
1121 | 449 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
1668 | 450 call system("rmdir /S/Q ".s:Escape(a:fname,0)) |
1121 | 451 else |
1668 | 452 call system("/bin/rm -rf ".s:Escape(a:fname,0)) |
530 | 453 endif |
454 " call Dret("Rmdir") | |
455 endfun | |
456 | |
457 " ------------------------------------------------------------------------ | |
458 " Modelines And Restoration: {{{1 | |
459 let &cpo= s:keepcpo | |
460 unlet s:keepcpo | |
1214 | 461 " vim:ts=8 fdm=marker |