Mercurial > vim
comparison runtime/autoload/tar.vim @ 2034:7bc41231fbc7
Update runtime files.
author | Bram Moolenaar <bram@zimbu.org> |
---|---|
date | Wed, 06 Jan 2010 20:54:52 +0100 |
parents | 5232b9862f23 |
children | e52d87a2bb3e |
comparison
equal
deleted
inserted
replaced
2033:de5a43c5eedc | 2034:7bc41231fbc7 |
---|---|
1 " tar.vim: Handles browsing tarfiles | 1 " tar.vim: Handles browsing tarfiles |
2 " AUTOLOAD PORTION | 2 " AUTOLOAD PORTION |
3 " Date: Aug 08, 2008 | 3 " Date: Dec 28, 2009 |
4 " Version: 23 + modifications by Bram | 4 " Version: 24 |
5 " Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> | 5 " Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> |
6 " License: Vim License (see vim's :help license) | 6 " License: Vim License (see vim's :help license) |
7 " | 7 " |
8 " Contains many ideas from Michael Toren's <tar.vim> | 8 " Contains many ideas from Michael Toren's <tar.vim> |
9 " | 9 " |
10 " Copyright: Copyright (C) 2005-2008 Charles E. Campbell, Jr. {{{1 | 10 " Copyright: Copyright (C) 2005-2009 Charles E. Campbell, Jr. {{{1 |
11 " Permission is hereby granted to use and distribute this code, | 11 " Permission is hereby granted to use and distribute this code, |
12 " with or without modifications, provided that this copyright | 12 " with or without modifications, provided that this copyright |
13 " notice is copied with it. Like anything else that's free, | 13 " notice is copied with it. Like anything else that's free, |
14 " tar.vim and tarPlugin.vim are provided *as is* and comes | 14 " tar.vim and tarPlugin.vim are provided *as is* and comes |
15 " with no warranty of any kind, either expressed or implied. | 15 " with no warranty of any kind, either expressed or implied. |
16 " By using this plugin, you agree that in no event will the | 16 " By using this plugin, you agree that in no event will the |
17 " copyright holder be liable for any damages resulting from | 17 " copyright holder be liable for any damages resulting from |
18 " the use of this software. | 18 " the use of this software. |
19 | 19 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
20 " --------------------------------------------------------------------- | 20 " --------------------------------------------------------------------- |
21 " Load Once: {{{1 | 21 " Load Once: {{{1 |
22 if &cp || exists("g:loaded_tar") | |
23 finish | |
24 endif | |
25 let g:loaded_tar= "v24" | |
26 if v:version < 702 | |
27 echohl WarningMsg | |
28 echo "***warning*** this version of tar needs vim 7.2" | |
29 echohl Normal | |
30 finish | |
31 endif | |
22 let s:keepcpo= &cpo | 32 let s:keepcpo= &cpo |
23 set cpo&vim | 33 set cpo&vim |
24 if &cp || exists("g:loaded_tar") || v:version < 700 | |
25 finish | |
26 endif | |
27 let g:loaded_tar= "v23b" | |
28 "call Decho("loading autoload/tar.vim") | 34 "call Decho("loading autoload/tar.vim") |
29 if v:version < 701 || (v:version == 701 && !has("patch299")) | |
30 echoerr "(autoload/tar.vim) need vim v7.1 with patchlevel 299" | |
31 endif | |
32 | 35 |
33 " --------------------------------------------------------------------- | 36 " --------------------------------------------------------------------- |
34 " Default Settings: {{{1 | 37 " Default Settings: {{{1 |
35 if !exists("g:tar_browseoptions") | 38 if !exists("g:tar_browseoptions") |
36 let g:tar_browseoptions= "Ptf" | 39 let g:tar_browseoptions= "Ptf" |
42 let g:tar_cmd= "tar" | 45 let g:tar_cmd= "tar" |
43 endif | 46 endif |
44 if !exists("g:tar_writeoptions") | 47 if !exists("g:tar_writeoptions") |
45 let g:tar_writeoptions= "uf" | 48 let g:tar_writeoptions= "uf" |
46 endif | 49 endif |
47 | 50 if !exists("g:tar_copycmd") |
51 if !exists("g:netrw_localcopycmd") | |
52 if has("win32") || has("win95") || has("win64") || has("win16") | |
53 if g:netrw_cygwin | |
54 let g:netrw_localcopycmd= "cp" | |
55 else | |
56 let g:netrw_localcopycmd= "copy" | |
57 endif | |
58 elseif has("unix") || has("macunix") | |
59 let g:netrw_localcopycmd= "cp" | |
60 else | |
61 let g:netrw_localcopycmd= "" | |
62 endif | |
63 endif | |
64 let g:tar_copycmd= g:netrw_localcopycmd | |
65 endif | |
48 if !exists("g:netrw_cygwin") | 66 if !exists("g:netrw_cygwin") |
49 if has("win32") || has("win95") || has("win64") || has("win16") | 67 if has("win32") || has("win95") || has("win64") || has("win16") |
50 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' | 68 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' |
51 let g:netrw_cygwin= 1 | 69 let g:netrw_cygwin= 1 |
52 else | 70 else |
53 let g:netrw_cygwin= 0 | 71 let g:netrw_cygwin= 0 |
54 endif | 72 endif |
55 else | 73 else |
56 let g:netrw_cygwin= 0 | 74 let g:netrw_cygwin= 0 |
57 endif | 75 endif |
76 endif | |
77 if !exists("g:tar_extractcmd") | |
78 let g:tar_extractcmd= "tar -xf" | |
58 endif | 79 endif |
59 | 80 |
60 " set up shell quoting character | 81 " set up shell quoting character |
61 if !exists("g:tar_shq") | 82 if !exists("g:tar_shq") |
62 if exists("&shq") && &shq != "" | 83 if exists("&shq") && &shq != "" |
86 | 107 |
87 " sanity checks | 108 " sanity checks |
88 if !executable(g:tar_cmd) | 109 if !executable(g:tar_cmd) |
89 redraw! | 110 redraw! |
90 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' | 111 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' |
91 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
92 let &report= repkeep | 112 let &report= repkeep |
93 " call Dret("tar#Browse") | 113 " call Dret("tar#Browse") |
94 return | 114 return |
95 endif | 115 endif |
96 if !filereadable(a:tarfile) | 116 if !filereadable(a:tarfile) |
97 " call Decho('a:tarfile<'.a:tarfile.'> not filereadable') | 117 " call Decho('a:tarfile<'.a:tarfile.'> not filereadable') |
98 if a:tarfile !~# '^\a\+://' | 118 if a:tarfile !~# '^\a\+://' |
99 " if its an url, don't complain, let url-handlers such as vim do its thing | 119 " if its an url, don't complain, let url-handlers such as vim do its thing |
100 redraw! | 120 redraw! |
101 echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None | 121 echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None |
102 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
103 endif | 122 endif |
104 let &report= repkeep | 123 let &report= repkeep |
105 " call Dret("tar#Browse : file<".a:tarfile."> not readable") | 124 " call Dret("tar#Browse : file<".a:tarfile."> not readable") |
106 return | 125 return |
107 endif | 126 endif |
128 $ | 147 $ |
129 | 148 |
130 let tarfile= a:tarfile | 149 let tarfile= a:tarfile |
131 if has("win32") && executable("cygpath") | 150 if has("win32") && executable("cygpath") |
132 " assuming cygwin | 151 " assuming cygwin |
133 let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile,0)),'\n$','','e') | 152 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
134 endif | 153 endif |
135 let curlast= line("$") | 154 let curlast= line("$") |
136 if tarfile =~# '\.\(gz\|tgz\)$' | 155 if tarfile =~# '\.\(gz\|tgz\)$' |
137 " call Decho("1: exe silent r! gzip -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | 156 " call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
138 exe "silent r! gzip -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " | 157 exe "silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
139 elseif tarfile =~# '\.lrp' | 158 elseif tarfile =~# '\.lrp' |
140 " call Decho("2: exe silent r! cat -- ".s:Escape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") | 159 " call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") |
141 exe "silent r! cat -- ".s:Escape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - " | 160 exe "silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - " |
142 elseif tarfile =~# '\.bz2$' | 161 elseif tarfile =~# '\.bz2$' |
143 " call Decho("3: exe silent r! bzip2 -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | 162 " call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
144 exe "silent r! bzip2 -d -c -- ".s:Escape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " | 163 exe "silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
164 elseif tarfile =~# '\.lzma$' | |
165 " call Decho("3: exe silent r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | |
166 exe "silent r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " | |
145 else | 167 else |
146 if tarfile =~ '^\s*-' | 168 if tarfile =~ '^\s*-' |
147 " A file name starting with a dash may be taken as an option. Prepend ./ to avoid that. | 169 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
148 let tarfile = substitute(tarfile, '-', './-', '') | 170 let tarfile = substitute(tarfile, '-', './-', '') |
149 endif | 171 endif |
150 " call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".s:Escape(tarfile,1)) | 172 " call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,0)) |
151 exe "silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".s:Escape(tarfile,1) | 173 exe "silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,1) |
152 endif | 174 endif |
153 if v:shell_error != 0 | 175 if v:shell_error != 0 |
154 redraw! | 176 redraw! |
155 echohl WarningMsg | echo "***warning*** (tar#Browse) please check your g:tar_browseoptions<".g:tar_browseoptions.">" | 177 echohl WarningMsg | echo "***warning*** (tar#Browse) please check your g:tar_browseoptions<".g:tar_browseoptions.">" |
156 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
157 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") | 178 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") |
158 return | 179 return |
159 endif | 180 endif |
160 if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)') | 181 if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)') |
161 redraw! | 182 redraw! |
162 echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None | 183 echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None |
163 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
164 silent %d | 184 silent %d |
165 let eikeep= &ei | 185 let eikeep= &ei |
166 set ei=BufReadCmd,FileReadCmd | 186 set ei=BufReadCmd,FileReadCmd |
167 exe "r ".fnameescape(a:tarfile) | 187 exe "r ".fnameescape(a:tarfile) |
168 let &ei= eikeep | 188 let &ei= eikeep |
187 let fname= getline(".") | 207 let fname= getline(".") |
188 " call Decho("fname<".fname.">") | 208 " call Decho("fname<".fname.">") |
189 | 209 |
190 if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' | 210 if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' |
191 redraw! | 211 redraw! |
192 echohl WarningMsg | echo '***error*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"; See :help tar-options' | 212 echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"' |
193 " call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') | 213 " call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') |
194 return | 214 return |
195 endif | 215 endif |
196 | 216 |
197 " sanity check | 217 " sanity check |
204 " about to make a new window, need to use w:tarfile | 224 " about to make a new window, need to use w:tarfile |
205 let tarfile= w:tarfile | 225 let tarfile= w:tarfile |
206 let curfile= expand("%") | 226 let curfile= expand("%") |
207 if has("win32") && executable("cygpath") | 227 if has("win32") && executable("cygpath") |
208 " assuming cygwin | 228 " assuming cygwin |
209 let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile,0)),'\n$','','e') | 229 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
210 endif | 230 endif |
211 | 231 |
212 new | 232 new |
213 if !exists("g:tar_nomax") || g:tar_nomax == 0 | 233 if !exists("g:tar_nomax") || g:tar_nomax == 0 |
214 wincmd _ | 234 wincmd _ |
229 set report=10 | 249 set report=10 |
230 let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','') | 250 let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','') |
231 let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','') | 251 let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','') |
232 if has("win32") && executable("cygpath") | 252 if has("win32") && executable("cygpath") |
233 " assuming cygwin | 253 " assuming cygwin |
234 let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile,0)),'\n$','','e') | 254 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
235 endif | 255 endif |
236 " call Decho("tarfile<".tarfile.">") | 256 " call Decho("tarfile<".tarfile.">") |
237 " call Decho("fname<".fname.">") | 257 " call Decho("fname<".fname.">") |
238 | 258 |
239 if fname =~ '\.gz$' && executable("zcat") | 259 if fname =~ '\.bz2$' && executable("bzcat") |
260 let decmp= "|bzcat" | |
261 let doro = 1 | |
262 elseif fname =~ '\.gz$' && executable("zcat") | |
240 let decmp= "|zcat" | 263 let decmp= "|zcat" |
241 let doro = 1 | 264 let doro = 1 |
242 elseif fname =~ '\.bz2$' && executable("bzcat") | 265 elseif fname =~ '\.lzma$' && executable("lzcat") |
243 let decmp= "|bzcat" | 266 let decmp= "|lzcat" |
244 let doro = 1 | 267 let doro = 1 |
245 else | 268 else |
246 let decmp="" | 269 let decmp="" |
247 let doro = 0 | 270 let doro = 0 |
248 if fname =~ '\.gz$\|\.bz2$\|\.Z$\|\.zip$' | 271 if fname =~ '\.bz2$\|\.gz$\|\.lzma$\|\.zip$\|\.Z$' |
249 setlocal bin | 272 setlocal bin |
250 endif | 273 endif |
251 endif | 274 endif |
252 | 275 |
253 if exists("g:tar_secure") | 276 if exists("g:tar_secure") |
254 let tar_secure= " -- " | 277 let tar_secure= " -- " |
255 else | 278 else |
256 let tar_secure= " " | 279 let tar_secure= " " |
257 endif | 280 endif |
258 if tarfile =~# '\.\(gz\|tgz\)$' | 281 if tarfile =~# '\.bz2$' |
259 " call Decho("5: exe silent r! gzip -d -c -- ".s:Escape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.s:Escape(fname,1)) | 282 " call Decho("7: exe silent r! bzip2 -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) |
260 exe "silent r! gzip -d -c -- ".s:Escape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp | 283 exe "silent r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
284 elseif tarfile =~# '\.\(gz\|tgz\)$' | |
285 " call Decho("5: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.shellescape(fname,1)) | |
286 exe "silent r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp | |
261 elseif tarfile =~# '\.lrp$' | 287 elseif tarfile =~# '\.lrp$' |
262 " call Decho("6: exe silent r! cat ".s:Escape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp) | 288 " call Decho("6: exe silent r! cat ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) |
263 exe "silent r! cat -- ".s:Escape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp | 289 exe "silent r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
264 elseif tarfile =~# '\.bz2$' | 290 elseif tarfile =~# '\.lzma$' |
265 " call Decho("7: exe silent r! bzip2 -d -c ".s:Escape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp) | 291 " call Decho("7: exe silent r! lzma -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) |
266 exe "silent r! bzip2 -d -c -- ".s:Escape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.s:Escape(fname,1).decmp | 292 exe "silent r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
267 else | 293 else |
268 if tarfile =~ '^\s*-' | 294 if tarfile =~ '^\s*-' |
269 " A file name starting with a dash may be taken as an option. Prepend ./ to avoid that. | 295 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
270 let tarfile = substitute(tarfile, '-', './-', '') | 296 let tarfile = substitute(tarfile, '-', './-', '') |
271 endif | 297 endif |
272 " call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions." "s:Escape(tarfile,1).tar_secure..s:Escape(fname,1).decmp) | 298 " call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions.tar_secure.shellescape(tarfile,1)." ".shellescape(fname,1).decmp) |
273 exe "silent r! ".g:tar_cmd." -".g:tar_readoptions." ".s:Escape(tarfile,1).tar_secure.s:Escape(fname,1).decmp | 299 exe "silent r! ".g:tar_cmd." -".g:tar_readoptions.shellescape(tarfile,1)." ".tar_secure.shellescape(fname,1).decmp |
274 endif | 300 endif |
275 | 301 |
276 if doro | 302 if doro |
277 " because the reverse process of compressing changed files back into the tarball is not currently supported | 303 " because the reverse process of compressing changed files back into the tarball is not currently supported |
278 setlocal ro | 304 setlocal ro |
296 let repkeep= &report | 322 let repkeep= &report |
297 set report=10 | 323 set report=10 |
298 | 324 |
299 if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-' | 325 if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-' |
300 redraw! | 326 redraw! |
301 echohl WarningMsg | echo '***error*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"; See :help tar-options' | 327 echohl WarningMsg | echo '***warning*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"' |
302 " call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"') | 328 " call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"') |
303 return | 329 return |
304 endif | 330 endif |
305 | 331 |
306 " sanity checks | 332 " sanity checks |
307 if !executable(g:tar_cmd) | 333 if !executable(g:tar_cmd) |
308 redraw! | 334 redraw! |
309 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' | 335 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' |
310 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
311 let &report= repkeep | 336 let &report= repkeep |
312 " call Dret("tar#Write") | 337 " call Dret("tar#Write") |
313 return | 338 return |
314 endif | 339 endif |
315 if !exists("*mkdir") | 340 if !exists("*mkdir") |
316 redraw! | 341 redraw! |
317 echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None | 342 echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None |
318 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
319 let &report= repkeep | 343 let &report= repkeep |
320 " call Dret("tar#Write") | 344 " call Dret("tar#Write") |
321 return | 345 return |
322 endif | 346 endif |
323 | 347 |
334 try | 358 try |
335 exe "cd ".fnameescape(tmpdir) | 359 exe "cd ".fnameescape(tmpdir) |
336 catch /^Vim\%((\a\+)\)\=:E344/ | 360 catch /^Vim\%((\a\+)\)\=:E344/ |
337 redraw! | 361 redraw! |
338 echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None | 362 echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None |
339 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
340 let &report= repkeep | 363 let &report= repkeep |
341 " call Dret("tar#Write") | 364 " call Dret("tar#Write") |
342 return | 365 return |
343 endtry | 366 endtry |
344 " call Decho("current directory now: ".getcwd()) | 367 " call Decho("current directory now: ".getcwd()) |
353 | 376 |
354 let tarfile = substitute(w:tarfile,'tarfile:\(.\{-}\)::.*$','\1','') | 377 let tarfile = substitute(w:tarfile,'tarfile:\(.\{-}\)::.*$','\1','') |
355 let fname = substitute(w:tarfile,'tarfile:.\{-}::\(.*\)$','\1','') | 378 let fname = substitute(w:tarfile,'tarfile:.\{-}::\(.*\)$','\1','') |
356 | 379 |
357 " handle compressed archives | 380 " handle compressed archives |
358 if tarfile =~# '\.gz' | 381 if tarfile =~# '\.bz2' |
359 call system("gzip -d -- ".s:Escape(tarfile,0)) | 382 call system("bzip2 -d -- ".shellescape(tarfile,0)) |
383 let tarfile = substitute(tarfile,'\.bz2','','e') | |
384 let compress= "bzip2 -- ".shellescape(tarfile,0) | |
385 " call Decho("compress<".compress.">") | |
386 elseif tarfile =~# '\.gz' | |
387 call system("gzip -d -- ".shellescape(tarfile,0)) | |
360 let tarfile = substitute(tarfile,'\.gz','','e') | 388 let tarfile = substitute(tarfile,'\.gz','','e') |
361 let compress= "gzip -- ".s:Escape(tarfile,0) | 389 let compress= "gzip -- ".shellescape(tarfile,0) |
390 " call Decho("compress<".compress.">") | |
391 elseif tarfile =~# '\.lzma' | |
392 call system("lzma -d -- ".shellescape(tarfile,0)) | |
393 let tarfile = substitute(tarfile,'\.lzma','','e') | |
394 let compress= "lzma -- ".shellescape(tarfile,0) | |
362 " call Decho("compress<".compress.">") | 395 " call Decho("compress<".compress.">") |
363 elseif tarfile =~# '\.tgz' | 396 elseif tarfile =~# '\.tgz' |
364 call system("gzip -d -- ".s:Escape(tarfile,0)) | 397 call system("gzip -d -- ".shellescape(tarfile,0)) |
365 let tarfile = substitute(tarfile,'\.tgz','.tar','e') | 398 let tarfile = substitute(tarfile,'\.tgz','.tar','e') |
366 let compress= "gzip -- ".s:Escape(tarfile,0) | 399 let compress= "gzip -- ".shellescape(tarfile,0) |
367 let tgz = 1 | 400 let tgz = 1 |
368 " call Decho("compress<".compress.">") | 401 " call Decho("compress<".compress.">") |
369 elseif tarfile =~# '\.bz2' | |
370 call system("bzip2 -d -- ".s:Escape(tarfile,0)) | |
371 let tarfile = substitute(tarfile,'\.bz2','','e') | |
372 let compress= "bzip2 -- ".s:Escape(tarfile,0) | |
373 " call Decho("compress<".compress.">") | |
374 endif | 402 endif |
375 " call Decho("tarfile<".tarfile.">") | 403 " call Decho("tarfile<".tarfile.">") |
376 | 404 |
377 if v:shell_error != 0 | 405 if v:shell_error != 0 |
378 redraw! | 406 redraw! |
379 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None | 407 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None |
380 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
381 else | 408 else |
382 | 409 |
383 " call Decho("tarfile<".tarfile."> fname<".fname.">") | 410 " call Decho("tarfile<".tarfile."> fname<".fname.">") |
384 | 411 |
385 if fname =~ '/' | 412 if fname =~ '/' |
386 let dirpath = substitute(fname,'/[^/]\+$','','e') | 413 let dirpath = substitute(fname,'/[^/]\+$','','e') |
387 if executable("cygpath") | 414 if executable("cygpath") |
388 let dirpath = substitute(system("cygpath ".s:Escape(dirpath, 0)),'\n','','e') | 415 let dirpath = substitute(system("cygpath ".shellescape(dirpath, 0)),'\n','','e') |
389 endif | 416 endif |
390 call mkdir(dirpath,"p") | 417 call mkdir(dirpath,"p") |
391 endif | 418 endif |
392 if tarfile !~ '/' | 419 if tarfile !~ '/' |
393 let tarfile= curdir.'/'.tarfile | 420 let tarfile= curdir.'/'.tarfile |
403 else | 430 else |
404 let tar_secure= " " | 431 let tar_secure= " " |
405 endif | 432 endif |
406 exe "w! ".fnameescape(fname) | 433 exe "w! ".fnameescape(fname) |
407 if executable("cygpath") | 434 if executable("cygpath") |
408 let tarfile = substitute(system("cygpath ".s:Escape(tarfile,0)),'\n','','e') | 435 let tarfile = substitute(system("cygpath ".shellescape(tarfile,0)),'\n','','e') |
409 endif | 436 endif |
410 | 437 |
411 " delete old file from tarfile | 438 " delete old file from tarfile |
412 " call Decho("system(".g:tar_cmd." --delete -f ".s:Escape(tarfile,0)." -- ".s:Escape(fname,0).")") | 439 " call Decho("system(".g:tar_cmd." --delete -f ".shellescape(tarfile,0)." -- ".shellescape(fname,0).")") |
413 call system(g:tar_cmd." --delete -f ".s:Escape(tarfile,0).tar_secure.s:Escape(fname,0)) | 440 call system(g:tar_cmd." --delete -f ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) |
414 if v:shell_error != 0 | 441 if v:shell_error != 0 |
415 redraw! | 442 redraw! |
416 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None | 443 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
417 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
418 else | 444 else |
419 | 445 |
420 " update tarfile with new file | 446 " update tarfile with new file |
421 " call Decho(g:tar_cmd." -".g:tar_writeoptions." ".s:Escape(tarfile,0).tar_secure.s:Escape(fname,0)) | 447 " call Decho(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) |
422 call system(g:tar_cmd." -".g:tar_writeoptions." ".s:Escape(tarfile,0).tar_secure.s:Escape(fname,0)) | 448 call system(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) |
423 if v:shell_error != 0 | 449 if v:shell_error != 0 |
424 redraw! | 450 redraw! |
425 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None | 451 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
426 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
427 elseif exists("compress") | 452 elseif exists("compress") |
428 " call Decho("call system(".compress.")") | 453 " call Decho("call system(".compress.")") |
429 call system(compress) | 454 call system(compress) |
430 if exists("tgz") | 455 if exists("tgz") |
431 " call Decho("rename(".tarfile.".gz,".substitute(tarfile,'\.tar$','.tgz','e').")") | 456 " call Decho("rename(".tarfile.".gz,".substitute(tarfile,'\.tar$','.tgz','e').")") |
437 " support writing tarfiles across a network | 462 " support writing tarfiles across a network |
438 if s:tblfile_{winnr()} =~ '^\a\+://' | 463 if s:tblfile_{winnr()} =~ '^\a\+://' |
439 " call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">") | 464 " call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">") |
440 let tblfile= s:tblfile_{winnr()} | 465 let tblfile= s:tblfile_{winnr()} |
441 1split|enew | 466 1split|enew |
442 let binkeep= &binary | 467 let binkeep= &l:binary |
443 let eikeep = &ei | 468 let eikeep = &ei |
444 set binary ei=all | 469 set binary ei=all |
445 exe "e! ".fnameescape(tarfile) | 470 exe "e! ".fnameescape(tarfile) |
446 call netrw#NetWrite(tblfile) | 471 call netrw#NetWrite(tblfile) |
447 let &ei = eikeep | 472 let &ei = eikeep |
448 let &binary = binkeep | 473 let &l:binary = binkeep |
449 q! | 474 q! |
450 unlet s:tblfile_{winnr()} | 475 unlet s:tblfile_{winnr()} |
451 endif | 476 endif |
452 endif | 477 endif |
453 | 478 |
460 let &report= repkeep | 485 let &report= repkeep |
461 " call Dret("tar#Write") | 486 " call Dret("tar#Write") |
462 endfun | 487 endfun |
463 | 488 |
464 " --------------------------------------------------------------------- | 489 " --------------------------------------------------------------------- |
465 " Rmdir: {{{2 | 490 " s:Rmdir: {{{2 |
466 fun! s:Rmdir(fname) | 491 fun! s:Rmdir(fname) |
467 " call Dfunc("Rmdir(fname<".a:fname.">)") | 492 " call Dfunc("Rmdir(fname<".a:fname.">)") |
468 if has("unix") | 493 if has("unix") |
469 call system("/bin/rm -rf -- ".s:Escape(a:fname,0)) | 494 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
470 elseif has("win32") || has("win95") || has("win64") || has("win16") | 495 elseif has("win32") || has("win95") || has("win64") || has("win16") |
471 if &shell =~? "sh$" | 496 if &shell =~? "sh$" |
472 call system("/bin/rm -rf -- ".s:Escape(a:fname,0)) | 497 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
473 else | 498 else |
474 call system("del /S ".s:Escape(a:fname,0)) | 499 call system("del /S ".shellescape(a:fname,0)) |
475 endif | 500 endif |
476 endif | 501 endif |
477 " call Dret("Rmdir") | 502 " call Dret("Rmdir") |
478 endfun | 503 endfun |
479 | 504 |
480 " --------------------------------------------------------------------- | 505 " --------------------------------------------------------------------- |
481 " s:Escape: {{{2 | 506 " tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2 |
482 fun s:Escape(name,isfilt) | 507 fun! tar#Vimuntar(...) |
483 " shellescape() was added by patch 7.0.111 | 508 " call Dfunc("tar#Vimuntar() a:0=".a:0." a:1<".(exists("a:1")? a:1 : "-n/a-").">") |
484 if exists("*shellescape") | 509 let tarball = expand("%") |
485 if a:isfilt | 510 " call Decho("tarball<".tarball.">") |
486 let qnameq= shellescape(a:name,1) | 511 let tarbase = substitute(tarball,'\..*$','','') |
512 " call Decho("tarbase<".tarbase.">") | |
513 let tarhome = expand("%:p") | |
514 if has("win32") || has("win95") || has("win64") || has("win16") | |
515 let tarhome= substitute(tarhome,'\\','/','g') | |
516 endif | |
517 let tarhome= substitute(tarhome,'/[^/]*$','','') | |
518 " call Decho("tarhome<".tarhome.">") | |
519 let tartail = expand("%:t") | |
520 " call Decho("tartail<".tartail.">") | |
521 let curdir = getcwd() | |
522 " call Decho("curdir <".curdir.">") | |
523 " set up vimhome | |
524 if a:0 > 0 && a:1 != "" | |
525 let vimhome= a:1 | |
526 else | |
527 let vimhome= vimball#VimballHome() | |
528 endif | |
529 " call Decho("vimhome<".vimhome.">") | |
530 | |
531 " call Decho("curdir<".curdir."> vimhome<".vimhome.">") | |
532 if simplify(curdir) != simplify(vimhome) | |
533 " copy (possibly compressed) tarball to .vim/vimfiles | |
534 " call Decho(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
535 call system(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
536 " call Decho("exe cd ".fnameescape(vimhome)) | |
537 exe "cd ".fnameescape(vimhome) | |
538 endif | |
539 " call Decho("getcwd<".getcwd().">") | |
540 | |
541 " if necessary, decompress the tarball; then, extract it | |
542 if tartail =~ '\.tgz' | |
543 if executable("gunzip") | |
544 silent exe "!gunzip ".shellescape(tartail) | |
545 elseif executable("gzip") | |
546 silent exe "!gzip -d ".shellescape(tartail) | |
487 else | 547 else |
488 let qnameq= shellescape(a:name) | 548 echoerr "unable to decompress<".tartail."> on this sytem" |
489 endif | 549 if simplify(curdir) != simplify(tarhome) |
490 else | 550 " remove decompressed tarball, restore directory |
491 let qnameq= g:tar_shq . a:name . g:tar_shq | 551 " call Decho("delete(".tartail.".tar)") |
492 endif | 552 call delete(tartail.".tar") |
493 return qnameq | 553 " call Decho("exe cd ".fnameescape(curdir)) |
554 exe "cd ".fnameescape(curdir) | |
555 endif | |
556 " call Dret("tar#Vimuntar") | |
557 return | |
558 endif | |
559 else | |
560 call vimball#Decompress(tartail,0) | |
561 endif | |
562 let extractcmd= netrw#WinPath(g:tar_extractcmd) | |
563 " call Decho("system(".extractcmd." ".shellescape(tarbase.".tar").")") | |
564 call system(extractcmd." ".shellescape(tarbase.".tar")) | |
565 | |
566 " set up help | |
567 if filereadable("doc/".tarbase.".txt") | |
568 " call Decho("exe helptags ".getcwd()."/doc") | |
569 exe "helptags ".getcwd()."/doc" | |
570 endif | |
571 | |
572 if simplify(tarhome) != simplify(vimhome) | |
573 " remove decompressed tarball, restore directory | |
574 call delete(vimhome."/".tarbase.".tar") | |
575 exe "cd ".fnameescape(curdir) | |
576 endif | |
577 | |
578 " call Dret("tar#Vimuntar") | |
494 endfun | 579 endfun |
495 | 580 |
496 " --------------------------------------------------------------------- | 581 " ===================================================================== |
497 " Modelines And Restoration: {{{1 | 582 " Modelines And Restoration: {{{1 |
498 let &cpo= s:keepcpo | 583 let &cpo= s:keepcpo |
499 unlet s:keepcpo | 584 unlet s:keepcpo |
500 " vim:ts=8 fdm=marker | 585 " vim:ts=8 fdm=marker |