Mercurial > vim
annotate runtime/autoload/tar.vim @ 9479:6149d1374ea0 v7.4.2020
commit https://github.com/vim/vim/commit/453f37dbfd6f8304a36ea84e40a9965404206186
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 10 18:33:59 2016 +0200
patch 7.4.2020
Problem: Can't build without +autocmd feature.
Solution: Adjust #ifdefs.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 10 Jul 2016 18:45:05 +0200 |
parents | 22fa3049e934 |
children | 8a1481e59d64 |
rev | line source |
---|---|
557 | 1 " tar.vim: Handles browsing tarfiles |
2 " AUTOLOAD PORTION | |
4339 | 3 " Date: Apr 17, 2013 |
4 " Version: 29 | |
5 " Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> | |
557 | 6 " License: Vim License (see vim's :help license) |
446 | 7 " |
557 | 8 " Contains many ideas from Michael Toren's <tar.vim> |
446 | 9 " |
4339 | 10 " Copyright: Copyright (C) 2005-2011 Charles E. Campbell {{{1 |
557 | 11 " Permission is hereby granted to use and distribute this code, |
12 " with or without modifications, provided that this copyright | |
13 " notice is copied with it. Like anything else that's free, | |
1624 | 14 " tar.vim and tarPlugin.vim are provided *as is* and comes |
15 " with no warranty of any kind, either expressed or implied. | |
16 " By using this plugin, you agree that in no event will the | |
17 " copyright holder be liable for any damages resulting from | |
18 " the use of this software. | |
2034 | 19 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 20 " --------------------------------------------------------------------- |
1125 | 21 " Load Once: {{{1 |
2034 | 22 if &cp || exists("g:loaded_tar") |
23 finish | |
24 endif | |
4339 | 25 let g:loaded_tar= "v29" |
2034 | 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 | |
557 | 32 let s:keepcpo= &cpo |
33 set cpo&vim | |
4339 | 34 "DechoTabOn |
819 | 35 "call Decho("loading autoload/tar.vim") |
557 | 36 |
37 " --------------------------------------------------------------------- | |
38 " Default Settings: {{{1 | |
39 if !exists("g:tar_browseoptions") | |
40 let g:tar_browseoptions= "Ptf" | |
41 endif | |
42 if !exists("g:tar_readoptions") | |
43 let g:tar_readoptions= "OPxf" | |
44 endif | |
819 | 45 if !exists("g:tar_cmd") |
46 let g:tar_cmd= "tar" | |
47 endif | |
557 | 48 if !exists("g:tar_writeoptions") |
49 let g:tar_writeoptions= "uf" | |
50 endif | |
2908 | 51 if !exists("g:netrw_cygwin") |
52 if has("win32") || has("win95") || has("win64") || has("win16") | |
53 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' | |
54 let g:netrw_cygwin= 1 | |
55 else | |
56 let g:netrw_cygwin= 0 | |
57 endif | |
58 else | |
59 let g:netrw_cygwin= 0 | |
60 endif | |
61 endif | |
2034 | 62 if !exists("g:tar_copycmd") |
63 if !exists("g:netrw_localcopycmd") | |
64 if has("win32") || has("win95") || has("win64") || has("win16") | |
65 if g:netrw_cygwin | |
66 let g:netrw_localcopycmd= "cp" | |
67 else | |
68 let g:netrw_localcopycmd= "copy" | |
69 endif | |
70 elseif has("unix") || has("macunix") | |
71 let g:netrw_localcopycmd= "cp" | |
72 else | |
73 let g:netrw_localcopycmd= "" | |
74 endif | |
75 endif | |
76 let g:tar_copycmd= g:netrw_localcopycmd | |
77 endif | |
78 if !exists("g:tar_extractcmd") | |
79 let g:tar_extractcmd= "tar -xf" | |
80 endif | |
1624 | 81 |
82 " set up shell quoting character | |
1125 | 83 if !exists("g:tar_shq") |
4339 | 84 if exists("+shq") && exists("&shq") && &shq != "" |
1624 | 85 let g:tar_shq= &shq |
86 elseif has("win32") || has("win95") || has("win64") || has("win16") | |
87 if exists("g:netrw_cygwin") && g:netrw_cygwin | |
88 let g:tar_shq= "'" | |
89 else | |
90 let g:tar_shq= '"' | |
91 endif | |
92 else | |
1125 | 93 let g:tar_shq= "'" |
94 endif | |
1624 | 95 " call Decho("g:tar_shq<".g:tar_shq.">") |
1125 | 96 endif |
557 | 97 |
98 " ---------------- | |
99 " Functions: {{{1 | |
100 " ---------------- | |
446 | 101 |
527 | 102 " --------------------------------------------------------------------- |
557 | 103 " tar#Browse: {{{2 |
104 fun! tar#Browse(tarfile) | |
105 " call Dfunc("tar#Browse(tarfile<".a:tarfile.">)") | |
569 | 106 let repkeep= &report |
107 set report=10 | |
446 | 108 |
557 | 109 " sanity checks |
819 | 110 if !executable(g:tar_cmd) |
1125 | 111 redraw! |
819 | 112 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' |
569 | 113 let &report= repkeep |
557 | 114 " call Dret("tar#Browse") |
115 return | |
116 endif | |
117 if !filereadable(a:tarfile) | |
819 | 118 " call Decho('a:tarfile<'.a:tarfile.'> not filereadable') |
557 | 119 if a:tarfile !~# '^\a\+://' |
120 " if its an url, don't complain, let url-handlers such as vim do its thing | |
1125 | 121 redraw! |
557 | 122 echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None |
123 endif | |
569 | 124 let &report= repkeep |
557 | 125 " call Dret("tar#Browse : file<".a:tarfile."> not readable") |
126 return | |
127 endif | |
128 if &ma != 1 | |
129 set ma | |
130 endif | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
131 let b:tarfile= a:tarfile |
446 | 132 |
557 | 133 setlocal noswapfile |
134 setlocal buftype=nofile | |
135 setlocal bufhidden=hide | |
136 setlocal nobuflisted | |
137 setlocal nowrap | |
138 set ft=tar | |
446 | 139 |
557 | 140 " give header |
819 | 141 " call Decho("printing header") |
1624 | 142 let lastline= line("$") |
143 call setline(lastline+1,'" tar.vim version '.g:loaded_tar) | |
144 call setline(lastline+2,'" Browsing tarfile '.a:tarfile) | |
145 call setline(lastline+3,'" Select a file with cursor and press ENTER') | |
2908 | 146 keepj $put ='' |
3281 | 147 keepj sil! 0d |
2908 | 148 keepj $ |
446 | 149 |
819 | 150 let tarfile= a:tarfile |
4339 | 151 if has("win32unix") && executable("cygpath") |
819 | 152 " assuming cygwin |
2034 | 153 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 154 endif |
857 | 155 let curlast= line("$") |
819 | 156 if tarfile =~# '\.\(gz\|tgz\)$' |
2034 | 157 " call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 158 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
1624 | 159 elseif tarfile =~# '\.lrp' |
2034 | 160 " call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 161 exe "sil! r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - " |
3281 | 162 elseif tarfile =~# '\.\(bz2\|tbz\|tb2\)$' |
2034 | 163 " call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 164 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
3281 | 165 elseif tarfile =~# '\.\(lzma\|tlz\)$' |
2034 | 166 " call Decho("3: exe silent r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 167 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
2426 | 168 elseif tarfile =~# '\.\(xz\|txz\)$' |
169 " call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | |
2908 | 170 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
557 | 171 else |
1702 | 172 if tarfile =~ '^\s*-' |
2034 | 173 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
1702 | 174 let tarfile = substitute(tarfile, '-', './-', '') |
175 endif | |
2034 | 176 " call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,0)) |
2908 | 177 exe "sil! r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,1) |
557 | 178 endif |
819 | 179 if v:shell_error != 0 |
1125 | 180 redraw! |
857 | 181 echohl WarningMsg | echo "***warning*** (tar#Browse) please check your g:tar_browseoptions<".g:tar_browseoptions.">" |
182 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") | |
183 return | |
184 endif | |
1125 | 185 if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)') |
186 redraw! | |
857 | 187 echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None |
2908 | 188 keepj sil! %d |
857 | 189 let eikeep= &ei |
190 set ei=BufReadCmd,FileReadCmd | |
1668 | 191 exe "r ".fnameescape(a:tarfile) |
857 | 192 let &ei= eikeep |
2908 | 193 keepj sil! 1d |
857 | 194 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") |
819 | 195 return |
196 endif | |
446 | 197 |
557 | 198 setlocal noma nomod ro |
199 noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr> | |
200 | |
569 | 201 let &report= repkeep |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
202 " call Dret("tar#Browse : b:tarfile<".b:tarfile.">") |
527 | 203 endfun |
204 | |
205 " --------------------------------------------------------------------- | |
557 | 206 " TarBrowseSelect: {{{2 |
207 fun! s:TarBrowseSelect() | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
208 " call Dfunc("TarBrowseSelect() b:tarfile<".b:tarfile."> curfile<".expand("%").">") |
569 | 209 let repkeep= &report |
210 set report=10 | |
557 | 211 let fname= getline(".") |
212 " call Decho("fname<".fname.">") | |
213 | |
1702 | 214 if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' |
215 redraw! | |
2034 | 216 echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"' |
1702 | 217 " call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') |
218 return | |
219 endif | |
220 | |
557 | 221 " sanity check |
222 if fname =~ '^"' | |
569 | 223 let &report= repkeep |
557 | 224 " call Dret("TarBrowseSelect") |
225 return | |
226 endif | |
227 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
228 " about to make a new window, need to use b:tarfile |
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
229 let tarfile= b:tarfile |
557 | 230 let curfile= expand("%") |
4339 | 231 if has("win32unix") && executable("cygpath") |
819 | 232 " assuming cygwin |
2034 | 233 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 234 endif |
557 | 235 |
236 new | |
1624 | 237 if !exists("g:tar_nomax") || g:tar_nomax == 0 |
238 wincmd _ | |
239 endif | |
557 | 240 let s:tblfile_{winnr()}= curfile |
1624 | 241 call tar#Read("tarfile:".tarfile.'::'.fname,1) |
557 | 242 filetype detect |
4339 | 243 set nomod |
244 exe 'com! -buffer -nargs=? -complete=file TarDiff :call tar#Diff(<q-args>,"'.fnameescape(fname).'")' | |
557 | 245 |
569 | 246 let &report= repkeep |
557 | 247 " call Dret("TarBrowseSelect : s:tblfile_".winnr()."<".s:tblfile_{winnr()}.">") |
248 endfun | |
249 | |
250 " --------------------------------------------------------------------- | |
251 " tar#Read: {{{2 | |
252 fun! tar#Read(fname,mode) | |
253 " call Dfunc("tar#Read(fname<".a:fname.">,mode=".a:mode.")") | |
569 | 254 let repkeep= &report |
255 set report=10 | |
1624 | 256 let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','') |
257 let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','') | |
4339 | 258 if has("win32unix") && executable("cygpath") |
819 | 259 " assuming cygwin |
2034 | 260 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 261 endif |
262 " call Decho("tarfile<".tarfile.">") | |
263 " call Decho("fname<".fname.">") | |
557 | 264 |
2034 | 265 if fname =~ '\.bz2$' && executable("bzcat") |
266 let decmp= "|bzcat" | |
267 let doro = 1 | |
268 elseif fname =~ '\.gz$' && executable("zcat") | |
1624 | 269 let decmp= "|zcat" |
270 let doro = 1 | |
2034 | 271 elseif fname =~ '\.lzma$' && executable("lzcat") |
272 let decmp= "|lzcat" | |
1624 | 273 let doro = 1 |
2426 | 274 elseif fname =~ '\.xz$' && executable("xzcat") |
275 let decmp= "|xzcat" | |
276 let doro = 1 | |
1624 | 277 else |
278 let decmp="" | |
279 let doro = 0 | |
2426 | 280 if fname =~ '\.bz2$\|\.gz$\|\.lzma$\|\.xz$\|\.zip$\|\.Z$' |
1624 | 281 setlocal bin |
282 endif | |
283 endif | |
284 | |
1702 | 285 if exists("g:tar_secure") |
286 let tar_secure= " -- " | |
287 else | |
288 let tar_secure= " " | |
289 endif | |
2034 | 290 if tarfile =~# '\.bz2$' |
291 " call Decho("7: exe silent r! bzip2 -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | |
2908 | 292 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2034 | 293 elseif tarfile =~# '\.\(gz\|tgz\)$' |
294 " call Decho("5: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.shellescape(fname,1)) | |
2908 | 295 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
1624 | 296 elseif tarfile =~# '\.lrp$' |
2034 | 297 " 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) |
2908 | 298 exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2034 | 299 elseif tarfile =~# '\.lzma$' |
300 " call Decho("7: exe silent r! lzma -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | |
2908 | 301 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2426 | 302 elseif tarfile =~# '\.\(xz\|txz\)$' |
303 " call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | |
2908 | 304 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
557 | 305 else |
1702 | 306 if tarfile =~ '^\s*-' |
2034 | 307 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
1702 | 308 let tarfile = substitute(tarfile, '-', './-', '') |
309 endif | |
2034 | 310 " call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions.tar_secure.shellescape(tarfile,1)." ".shellescape(fname,1).decmp) |
311 exe "silent r! ".g:tar_cmd." -".g:tar_readoptions.shellescape(tarfile,1)." ".tar_secure.shellescape(fname,1).decmp | |
557 | 312 endif |
1624 | 313 |
314 if doro | |
315 " because the reverse process of compressing changed files back into the tarball is not currently supported | |
316 setlocal ro | |
317 endif | |
318 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
319 let b:tarfile= a:fname |
1668 | 320 exe "file tarfile::".fnameescape(fname) |
557 | 321 |
322 " cleanup | |
2908 | 323 keepj sil! 0d |
557 | 324 set nomod |
325 | |
569 | 326 let &report= repkeep |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
327 " call Dret("tar#Read : b:tarfile<".b:tarfile.">") |
557 | 328 endfun |
329 | |
330 " --------------------------------------------------------------------- | |
331 " tar#Write: {{{2 | |
332 fun! tar#Write(fname) | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
333 " call Dfunc("tar#Write(fname<".a:fname.">) b:tarfile<".b:tarfile."> tblfile_".winnr()."<".s:tblfile_{winnr()}.">") |
569 | 334 let repkeep= &report |
335 set report=10 | |
557 | 336 |
1702 | 337 if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-' |
338 redraw! | |
2034 | 339 echohl WarningMsg | echo '***warning*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"' |
1702 | 340 " call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"') |
341 return | |
342 endif | |
343 | |
527 | 344 " sanity checks |
819 | 345 if !executable(g:tar_cmd) |
1125 | 346 redraw! |
819 | 347 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' |
569 | 348 let &report= repkeep |
527 | 349 " call Dret("tar#Write") |
350 return | |
351 endif | |
352 if !exists("*mkdir") | |
1125 | 353 redraw! |
557 | 354 echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None |
569 | 355 let &report= repkeep |
527 | 356 " call Dret("tar#Write") |
357 return | |
358 endif | |
359 | |
360 let curdir= getcwd() | |
361 let tmpdir= tempname() | |
362 " call Decho("orig tempname<".tmpdir.">") | |
363 if tmpdir =~ '\.' | |
364 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | |
365 endif | |
366 " call Decho("tmpdir<".tmpdir.">") | |
367 call mkdir(tmpdir,"p") | |
368 | |
369 " attempt to change to the indicated directory | |
370 try | |
1624 | 371 exe "cd ".fnameescape(tmpdir) |
527 | 372 catch /^Vim\%((\a\+)\)\=:E344/ |
1125 | 373 redraw! |
557 | 374 echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None |
569 | 375 let &report= repkeep |
527 | 376 " call Dret("tar#Write") |
377 return | |
378 endtry | |
379 " call Decho("current directory now: ".getcwd()) | |
446 | 380 |
557 | 381 " place temporary files under .../_ZIPVIM_/ |
382 if isdirectory("_ZIPVIM_") | |
383 call s:Rmdir("_ZIPVIM_") | |
527 | 384 endif |
557 | 385 call mkdir("_ZIPVIM_") |
386 cd _ZIPVIM_ | |
527 | 387 " call Decho("current directory now: ".getcwd()) |
388 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
389 let tarfile = substitute(b:tarfile,'tarfile:\(.\{-}\)::.*$','\1','') |
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
390 let fname = substitute(b:tarfile,'tarfile:.\{-}::\(.*\)$','\1','') |
557 | 391 |
392 " handle compressed archives | |
2034 | 393 if tarfile =~# '\.bz2' |
394 call system("bzip2 -d -- ".shellescape(tarfile,0)) | |
395 let tarfile = substitute(tarfile,'\.bz2','','e') | |
396 let compress= "bzip2 -- ".shellescape(tarfile,0) | |
397 " call Decho("compress<".compress.">") | |
398 elseif tarfile =~# '\.gz' | |
399 call system("gzip -d -- ".shellescape(tarfile,0)) | |
557 | 400 let tarfile = substitute(tarfile,'\.gz','','e') |
2034 | 401 let compress= "gzip -- ".shellescape(tarfile,0) |
402 " call Decho("compress<".compress.">") | |
557 | 403 elseif tarfile =~# '\.tgz' |
2034 | 404 call system("gzip -d -- ".shellescape(tarfile,0)) |
557 | 405 let tarfile = substitute(tarfile,'\.tgz','.tar','e') |
2034 | 406 let compress= "gzip -- ".shellescape(tarfile,0) |
557 | 407 let tgz = 1 |
1702 | 408 " call Decho("compress<".compress.">") |
2426 | 409 elseif tarfile =~# '\.xz' |
410 call system("xz -d -- ".shellescape(tarfile,0)) | |
411 let tarfile = substitute(tarfile,'\.xz','','e') | |
412 let compress= "xz -- ".shellescape(tarfile,0) | |
413 " call Decho("compress<".compress.">") | |
414 elseif tarfile =~# '\.lzma' | |
415 call system("lzma -d -- ".shellescape(tarfile,0)) | |
416 let tarfile = substitute(tarfile,'\.lzma','','e') | |
417 let compress= "lzma -- ".shellescape(tarfile,0) | |
418 " call Decho("compress<".compress.">") | |
527 | 419 endif |
1624 | 420 " call Decho("tarfile<".tarfile.">") |
527 | 421 |
422 if v:shell_error != 0 | |
1125 | 423 redraw! |
557 | 424 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None |
527 | 425 else |
557 | 426 |
427 " call Decho("tarfile<".tarfile."> fname<".fname.">") | |
428 | |
624 | 429 if fname =~ '/' |
430 let dirpath = substitute(fname,'/[^/]\+$','','e') | |
4339 | 431 if has("win32unix") && executable("cygpath") |
2034 | 432 let dirpath = substitute(system("cygpath ".shellescape(dirpath, 0)),'\n','','e') |
624 | 433 endif |
434 call mkdir(dirpath,"p") | |
435 endif | |
557 | 436 if tarfile !~ '/' |
437 let tarfile= curdir.'/'.tarfile | |
438 endif | |
1702 | 439 if tarfile =~ '^\s*-' |
440 " A file name starting with a dash may be taken as an option. Prepend ./ to avoid that. | |
441 let tarfile = substitute(tarfile, '-', './-', '') | |
442 endif | |
557 | 443 " call Decho("tarfile<".tarfile."> fname<".fname.">") |
444 | |
1702 | 445 if exists("g:tar_secure") |
446 let tar_secure= " -- " | |
447 else | |
448 let tar_secure= " " | |
449 endif | |
1624 | 450 exe "w! ".fnameescape(fname) |
4339 | 451 if has("win32unix") && executable("cygpath") |
2034 | 452 let tarfile = substitute(system("cygpath ".shellescape(tarfile,0)),'\n','','e') |
557 | 453 endif |
454 | |
455 " delete old file from tarfile | |
2034 | 456 " call Decho("system(".g:tar_cmd." --delete -f ".shellescape(tarfile,0)." -- ".shellescape(fname,0).")") |
457 call system(g:tar_cmd." --delete -f ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) | |
557 | 458 if v:shell_error != 0 |
1125 | 459 redraw! |
1624 | 460 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
557 | 461 else |
462 | |
463 " update tarfile with new file | |
2034 | 464 " call Decho(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) |
465 call system(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) | |
557 | 466 if v:shell_error != 0 |
1125 | 467 redraw! |
1624 | 468 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
557 | 469 elseif exists("compress") |
470 " call Decho("call system(".compress.")") | |
471 call system(compress) | |
472 if exists("tgz") | |
473 " call Decho("rename(".tarfile.".gz,".substitute(tarfile,'\.tar$','.tgz','e').")") | |
474 call rename(tarfile.".gz",substitute(tarfile,'\.tar$','.tgz','e')) | |
475 endif | |
476 endif | |
477 endif | |
478 | |
479 " support writing tarfiles across a network | |
480 if s:tblfile_{winnr()} =~ '^\a\+://' | |
481 " call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">") | |
482 let tblfile= s:tblfile_{winnr()} | |
483 1split|enew | |
2034 | 484 let binkeep= &l:binary |
557 | 485 let eikeep = &ei |
486 set binary ei=all | |
1668 | 487 exe "e! ".fnameescape(tarfile) |
557 | 488 call netrw#NetWrite(tblfile) |
2034 | 489 let &ei = eikeep |
490 let &l:binary = binkeep | |
557 | 491 q! |
492 unlet s:tblfile_{winnr()} | |
493 endif | |
527 | 494 endif |
495 | |
496 " cleanup and restore current directory | |
497 cd .. | |
557 | 498 call s:Rmdir("_ZIPVIM_") |
1668 | 499 exe "cd ".fnameescape(curdir) |
527 | 500 setlocal nomod |
501 | |
569 | 502 let &report= repkeep |
527 | 503 " call Dret("tar#Write") |
504 endfun | |
505 | |
506 " --------------------------------------------------------------------- | |
4339 | 507 " tar#Diff: {{{2 |
508 fun! tar#Diff(userfname,fname) | |
509 " call Dfunc("tar#Diff(userfname<".a:userfname."> fname<".a:fname.")") | |
510 let fname= a:fname | |
511 if a:userfname != "" | |
512 let fname= a:userfname | |
513 endif | |
514 if filereadable(fname) | |
515 " sets current file (from tarball) for diff'ing | |
516 " splits window vertically | |
517 " opens original file, sets it for diff'ing | |
518 " sets up b:tardiff_otherbuf variables so each buffer knows about the other (for closing purposes) | |
519 diffthis | |
520 wincmd v | |
521 exe "e ".fnameescape(fname) | |
522 diffthis | |
523 else | |
524 redraw! | |
525 echo "***warning*** unable to read file<".fname.">" | |
526 endif | |
527 " call Dret("tar#Diff") | |
528 endfun | |
529 | |
530 " --------------------------------------------------------------------- | |
2034 | 531 " s:Rmdir: {{{2 |
527 | 532 fun! s:Rmdir(fname) |
533 " call Dfunc("Rmdir(fname<".a:fname.">)") | |
534 if has("unix") | |
2034 | 535 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
527 | 536 elseif has("win32") || has("win95") || has("win64") || has("win16") |
537 if &shell =~? "sh$" | |
2034 | 538 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
527 | 539 else |
2034 | 540 call system("del /S ".shellescape(a:fname,0)) |
527 | 541 endif |
542 endif | |
543 " call Dret("Rmdir") | |
544 endfun | |
545 | |
1624 | 546 " --------------------------------------------------------------------- |
2034 | 547 " tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2 |
548 fun! tar#Vimuntar(...) | |
549 " call Dfunc("tar#Vimuntar() a:0=".a:0." a:1<".(exists("a:1")? a:1 : "-n/a-").">") | |
550 let tarball = expand("%") | |
551 " call Decho("tarball<".tarball.">") | |
552 let tarbase = substitute(tarball,'\..*$','','') | |
553 " call Decho("tarbase<".tarbase.">") | |
554 let tarhome = expand("%:p") | |
555 if has("win32") || has("win95") || has("win64") || has("win16") | |
556 let tarhome= substitute(tarhome,'\\','/','g') | |
557 endif | |
558 let tarhome= substitute(tarhome,'/[^/]*$','','') | |
559 " call Decho("tarhome<".tarhome.">") | |
560 let tartail = expand("%:t") | |
561 " call Decho("tartail<".tartail.">") | |
562 let curdir = getcwd() | |
563 " call Decho("curdir <".curdir.">") | |
564 " set up vimhome | |
565 if a:0 > 0 && a:1 != "" | |
566 let vimhome= a:1 | |
567 else | |
568 let vimhome= vimball#VimballHome() | |
569 endif | |
570 " call Decho("vimhome<".vimhome.">") | |
571 | |
572 " call Decho("curdir<".curdir."> vimhome<".vimhome.">") | |
573 if simplify(curdir) != simplify(vimhome) | |
574 " copy (possibly compressed) tarball to .vim/vimfiles | |
575 " call Decho(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
576 call system(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
577 " call Decho("exe cd ".fnameescape(vimhome)) | |
578 exe "cd ".fnameescape(vimhome) | |
579 endif | |
580 " call Decho("getcwd<".getcwd().">") | |
581 | |
582 " if necessary, decompress the tarball; then, extract it | |
583 if tartail =~ '\.tgz' | |
584 if executable("gunzip") | |
585 silent exe "!gunzip ".shellescape(tartail) | |
586 elseif executable("gzip") | |
587 silent exe "!gzip -d ".shellescape(tartail) | |
1668 | 588 else |
2034 | 589 echoerr "unable to decompress<".tartail."> on this sytem" |
590 if simplify(curdir) != simplify(tarhome) | |
591 " remove decompressed tarball, restore directory | |
592 " call Decho("delete(".tartail.".tar)") | |
593 call delete(tartail.".tar") | |
594 " call Decho("exe cd ".fnameescape(curdir)) | |
595 exe "cd ".fnameescape(curdir) | |
596 endif | |
597 " call Dret("tar#Vimuntar") | |
598 return | |
1668 | 599 endif |
1624 | 600 else |
2034 | 601 call vimball#Decompress(tartail,0) |
1624 | 602 endif |
2034 | 603 let extractcmd= netrw#WinPath(g:tar_extractcmd) |
604 " call Decho("system(".extractcmd." ".shellescape(tarbase.".tar").")") | |
605 call system(extractcmd." ".shellescape(tarbase.".tar")) | |
606 | |
607 " set up help | |
608 if filereadable("doc/".tarbase.".txt") | |
609 " call Decho("exe helptags ".getcwd()."/doc") | |
610 exe "helptags ".getcwd()."/doc" | |
611 endif | |
612 | |
613 if simplify(tarhome) != simplify(vimhome) | |
614 " remove decompressed tarball, restore directory | |
615 call delete(vimhome."/".tarbase.".tar") | |
616 exe "cd ".fnameescape(curdir) | |
617 endif | |
618 | |
619 " call Dret("tar#Vimuntar") | |
1624 | 620 endfun |
621 | |
2034 | 622 " ===================================================================== |
557 | 623 " Modelines And Restoration: {{{1 |
624 let &cpo= s:keepcpo | |
625 unlet s:keepcpo | |
1624 | 626 " vim:ts=8 fdm=marker |