Mercurial > vim
annotate runtime/autoload/tar.vim @ 19750:aa674de6d813 v8.2.0431
patch 8.2.0431: some compilers don't support using e for Esc
Commit: https://github.com/vim/vim/commit/56ba21a156c723d92a1929e2c500be7295efb0a8
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 23 19:17:29 2020 +0100
patch 8.2.0431: some compilers don't support using \e for Esc
Problem: Some compilers don't support using \e for Esc. (Yegappan
Lakshmanan)
Solution: use \033 instead.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 23 Mar 2020 19:30:04 +0100 |
parents | 9b7f90e56753 |
children | 29c5f168c6fd |
rev | line source |
---|---|
557 | 1 " tar.vim: Handles browsing tarfiles |
2 " AUTOLOAD PORTION | |
19099 | 3 " Date: Jan 07, 2020 |
4 " Version: 32 | |
5 " Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> | |
6 " License: Vim License (see vim's :help license) | |
446 | 7 " |
557 | 8 " Contains many ideas from Michael Toren's <tar.vim> |
446 | 9 " |
19099 | 10 " Copyright: Copyright (C) 2005-2017 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 | |
19099 | 25 let g:loaded_tar= "v32" |
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 | |
19099 | 51 if !exists("g:tar_delfile") |
52 let g:tar_delfile="--delete -f" | |
53 endif | |
2908 | 54 if !exists("g:netrw_cygwin") |
55 if has("win32") || has("win95") || has("win64") || has("win16") | |
56 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' | |
57 let g:netrw_cygwin= 1 | |
58 else | |
59 let g:netrw_cygwin= 0 | |
60 endif | |
61 else | |
62 let g:netrw_cygwin= 0 | |
63 endif | |
64 endif | |
2034 | 65 if !exists("g:tar_copycmd") |
66 if !exists("g:netrw_localcopycmd") | |
67 if has("win32") || has("win95") || has("win64") || has("win16") | |
68 if g:netrw_cygwin | |
69 let g:netrw_localcopycmd= "cp" | |
70 else | |
71 let g:netrw_localcopycmd= "copy" | |
72 endif | |
73 elseif has("unix") || has("macunix") | |
74 let g:netrw_localcopycmd= "cp" | |
75 else | |
76 let g:netrw_localcopycmd= "" | |
77 endif | |
78 endif | |
79 let g:tar_copycmd= g:netrw_localcopycmd | |
80 endif | |
81 if !exists("g:tar_extractcmd") | |
82 let g:tar_extractcmd= "tar -xf" | |
83 endif | |
1624 | 84 |
85 " set up shell quoting character | |
1125 | 86 if !exists("g:tar_shq") |
4339 | 87 if exists("+shq") && exists("&shq") && &shq != "" |
1624 | 88 let g:tar_shq= &shq |
89 elseif has("win32") || has("win95") || has("win64") || has("win16") | |
90 if exists("g:netrw_cygwin") && g:netrw_cygwin | |
91 let g:tar_shq= "'" | |
92 else | |
93 let g:tar_shq= '"' | |
94 endif | |
95 else | |
1125 | 96 let g:tar_shq= "'" |
97 endif | |
1624 | 98 " call Decho("g:tar_shq<".g:tar_shq.">") |
1125 | 99 endif |
557 | 100 |
101 " ---------------- | |
102 " Functions: {{{1 | |
103 " ---------------- | |
446 | 104 |
527 | 105 " --------------------------------------------------------------------- |
557 | 106 " tar#Browse: {{{2 |
107 fun! tar#Browse(tarfile) | |
108 " call Dfunc("tar#Browse(tarfile<".a:tarfile.">)") | |
569 | 109 let repkeep= &report |
110 set report=10 | |
446 | 111 |
557 | 112 " sanity checks |
819 | 113 if !executable(g:tar_cmd) |
1125 | 114 redraw! |
19099 | 115 " call Decho('***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system') |
819 | 116 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' |
569 | 117 let &report= repkeep |
557 | 118 " call Dret("tar#Browse") |
119 return | |
120 endif | |
121 if !filereadable(a:tarfile) | |
819 | 122 " call Decho('a:tarfile<'.a:tarfile.'> not filereadable') |
557 | 123 if a:tarfile !~# '^\a\+://' |
19116 | 124 " if it's an url, don't complain, let url-handlers such as vim do its thing |
1125 | 125 redraw! |
19099 | 126 " call Decho("***error*** (tar#Browse) File not readable<".a:tarfile.">") |
557 | 127 echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None |
128 endif | |
569 | 129 let &report= repkeep |
557 | 130 " call Dret("tar#Browse : file<".a:tarfile."> not readable") |
131 return | |
132 endif | |
133 if &ma != 1 | |
134 set ma | |
135 endif | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
136 let b:tarfile= a:tarfile |
446 | 137 |
557 | 138 setlocal noswapfile |
139 setlocal buftype=nofile | |
140 setlocal bufhidden=hide | |
141 setlocal nobuflisted | |
142 setlocal nowrap | |
143 set ft=tar | |
446 | 144 |
557 | 145 " give header |
819 | 146 " call Decho("printing header") |
1624 | 147 let lastline= line("$") |
148 call setline(lastline+1,'" tar.vim version '.g:loaded_tar) | |
149 call setline(lastline+2,'" Browsing tarfile '.a:tarfile) | |
150 call setline(lastline+3,'" Select a file with cursor and press ENTER') | |
2908 | 151 keepj $put ='' |
3281 | 152 keepj sil! 0d |
2908 | 153 keepj $ |
446 | 154 |
819 | 155 let tarfile= a:tarfile |
4339 | 156 if has("win32unix") && executable("cygpath") |
819 | 157 " assuming cygwin |
2034 | 158 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 159 endif |
19099 | 160 let curlast= line("$") |
14668 | 161 |
19099 | 162 if tarfile =~# '\.\(gz\)$' |
2034 | 163 " call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
19099 | 164 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
165 | |
166 elseif tarfile =~# '\.\(tgz\)$' || tarfile =~# '\.\(tbz\)$' || tarfile =~# '\.\(txz\)$' | |
167 if has("unix") && executable("file") | |
168 let filekind= system("file ".shellescape(tarfile,1)) =~ "bzip2" | |
169 else | |
170 let filekind= "" | |
171 endif | |
172 | |
173 if filekind =~ "bzip2" | |
174 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " | |
175 elseif filekind =~ "XZ" | |
176 exe "sil! r! xz -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " | |
177 else | |
178 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " | |
179 endif | |
180 | |
1624 | 181 elseif tarfile =~# '\.lrp' |
2034 | 182 " call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") |
14679
ba010fa2bcba
patch 8.1.0352: browsing compressed tar files does not always work
Christian Brabandt <cb@256bit.org>
parents:
14668
diff
changeset
|
183 exe "sil! r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - " |
3281 | 184 elseif tarfile =~# '\.\(bz2\|tbz\|tb2\)$' |
2034 | 185 " call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 186 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
3281 | 187 elseif tarfile =~# '\.\(lzma\|tlz\)$' |
2034 | 188 " call Decho("3: exe silent r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 189 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
2426 | 190 elseif tarfile =~# '\.\(xz\|txz\)$' |
191 " call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | |
2908 | 192 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
557 | 193 else |
1702 | 194 if tarfile =~ '^\s*-' |
2034 | 195 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
1702 | 196 let tarfile = substitute(tarfile, '-', './-', '') |
197 endif | |
2034 | 198 " call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,0)) |
2908 | 199 exe "sil! r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,1) |
557 | 200 endif |
819 | 201 if v:shell_error != 0 |
1125 | 202 redraw! |
857 | 203 echohl WarningMsg | echo "***warning*** (tar#Browse) please check your g:tar_browseoptions<".g:tar_browseoptions.">" |
204 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") | |
205 return | |
206 endif | |
19099 | 207 if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~# '\c\%(warning\|error\|inappropriate\|unrecognized\)') |
1125 | 208 redraw! |
857 | 209 echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None |
2908 | 210 keepj sil! %d |
857 | 211 let eikeep= &ei |
212 set ei=BufReadCmd,FileReadCmd | |
1668 | 213 exe "r ".fnameescape(a:tarfile) |
857 | 214 let &ei= eikeep |
2908 | 215 keepj sil! 1d |
857 | 216 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") |
819 | 217 return |
218 endif | |
446 | 219 |
19099 | 220 " set up maps supported for tar |
557 | 221 setlocal noma nomod ro |
19099 | 222 noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr> |
223 noremap <silent> <buffer> x :call tar#Extract()<cr> | |
224 if &mouse != "" | |
225 noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>TarBrowseSelect()<cr> | |
226 endif | |
557 | 227 |
569 | 228 let &report= repkeep |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
229 " call Dret("tar#Browse : b:tarfile<".b:tarfile.">") |
527 | 230 endfun |
231 | |
232 " --------------------------------------------------------------------- | |
557 | 233 " TarBrowseSelect: {{{2 |
234 fun! s:TarBrowseSelect() | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
235 " call Dfunc("TarBrowseSelect() b:tarfile<".b:tarfile."> curfile<".expand("%").">") |
569 | 236 let repkeep= &report |
237 set report=10 | |
557 | 238 let fname= getline(".") |
239 " call Decho("fname<".fname.">") | |
240 | |
1702 | 241 if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' |
242 redraw! | |
2034 | 243 echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"' |
1702 | 244 " call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') |
245 return | |
246 endif | |
247 | |
557 | 248 " sanity check |
249 if fname =~ '^"' | |
569 | 250 let &report= repkeep |
557 | 251 " call Dret("TarBrowseSelect") |
252 return | |
253 endif | |
254 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
255 " 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
|
256 let tarfile= b:tarfile |
557 | 257 let curfile= expand("%") |
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 |
557 | 262 |
19099 | 263 " open a new window (tar#Read will read a file into it) |
264 noswapfile new | |
1624 | 265 if !exists("g:tar_nomax") || g:tar_nomax == 0 |
266 wincmd _ | |
267 endif | |
557 | 268 let s:tblfile_{winnr()}= curfile |
1624 | 269 call tar#Read("tarfile:".tarfile.'::'.fname,1) |
557 | 270 filetype detect |
4339 | 271 set nomod |
272 exe 'com! -buffer -nargs=? -complete=file TarDiff :call tar#Diff(<q-args>,"'.fnameescape(fname).'")' | |
557 | 273 |
569 | 274 let &report= repkeep |
557 | 275 " call Dret("TarBrowseSelect : s:tblfile_".winnr()."<".s:tblfile_{winnr()}.">") |
276 endfun | |
277 | |
278 " --------------------------------------------------------------------- | |
279 " tar#Read: {{{2 | |
280 fun! tar#Read(fname,mode) | |
281 " call Dfunc("tar#Read(fname<".a:fname.">,mode=".a:mode.")") | |
569 | 282 let repkeep= &report |
283 set report=10 | |
1624 | 284 let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','') |
285 let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','') | |
4339 | 286 if has("win32unix") && executable("cygpath") |
819 | 287 " assuming cygwin |
2034 | 288 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 289 endif |
290 " call Decho("tarfile<".tarfile.">") | |
291 " call Decho("fname<".fname.">") | |
557 | 292 |
2034 | 293 if fname =~ '\.bz2$' && executable("bzcat") |
294 let decmp= "|bzcat" | |
295 let doro = 1 | |
19099 | 296 elseif fname =~ '\.t\=gz$' && executable("zcat") |
1624 | 297 let decmp= "|zcat" |
298 let doro = 1 | |
2034 | 299 elseif fname =~ '\.lzma$' && executable("lzcat") |
300 let decmp= "|lzcat" | |
1624 | 301 let doro = 1 |
2426 | 302 elseif fname =~ '\.xz$' && executable("xzcat") |
303 let decmp= "|xzcat" | |
304 let doro = 1 | |
1624 | 305 else |
306 let decmp="" | |
307 let doro = 0 | |
2426 | 308 if fname =~ '\.bz2$\|\.gz$\|\.lzma$\|\.xz$\|\.zip$\|\.Z$' |
1624 | 309 setlocal bin |
310 endif | |
311 endif | |
312 | |
1702 | 313 if exists("g:tar_secure") |
314 let tar_secure= " -- " | |
315 else | |
316 let tar_secure= " " | |
317 endif | |
14668 | 318 |
2034 | 319 if tarfile =~# '\.bz2$' |
2908 | 320 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
19099 | 321 elseif tarfile =~# '\.\(gz\)$' |
322 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp | |
323 | |
324 elseif tarfile =~# '\(\.tgz\|\.tbz\|\.txz\)' | |
325 if has("unix") && executable("file") | |
326 let filekind= system("file ".shellescape(tarfile,1)) | |
327 else | |
328 let filekind= "" | |
329 endif | |
330 if filekind =~ "bzip2" | |
331 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp | |
332 elseif filekind =~ "XZ" | |
333 exe "sil! r! xz -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp | |
334 else | |
335 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp | |
336 endif | |
337 | |
1624 | 338 elseif tarfile =~# '\.lrp$' |
14679
ba010fa2bcba
patch 8.1.0352: browsing compressed tar files does not always work
Christian Brabandt <cb@256bit.org>
parents:
14668
diff
changeset
|
339 exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2034 | 340 elseif tarfile =~# '\.lzma$' |
2908 | 341 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2426 | 342 elseif tarfile =~# '\.\(xz\|txz\)$' |
2908 | 343 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
557 | 344 else |
1702 | 345 if tarfile =~ '^\s*-' |
2034 | 346 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
1702 | 347 let tarfile = substitute(tarfile, '-', './-', '') |
348 endif | |
2034 | 349 " call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions.tar_secure.shellescape(tarfile,1)." ".shellescape(fname,1).decmp) |
350 exe "silent r! ".g:tar_cmd." -".g:tar_readoptions.shellescape(tarfile,1)." ".tar_secure.shellescape(fname,1).decmp | |
557 | 351 endif |
1624 | 352 |
353 if doro | |
354 " because the reverse process of compressing changed files back into the tarball is not currently supported | |
355 setlocal ro | |
356 endif | |
357 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
358 let b:tarfile= a:fname |
1668 | 359 exe "file tarfile::".fnameescape(fname) |
557 | 360 |
361 " cleanup | |
2908 | 362 keepj sil! 0d |
557 | 363 set nomod |
364 | |
569 | 365 let &report= repkeep |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
366 " call Dret("tar#Read : b:tarfile<".b:tarfile.">") |
557 | 367 endfun |
368 | |
369 " --------------------------------------------------------------------- | |
370 " tar#Write: {{{2 | |
371 fun! tar#Write(fname) | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
372 " call Dfunc("tar#Write(fname<".a:fname.">) b:tarfile<".b:tarfile."> tblfile_".winnr()."<".s:tblfile_{winnr()}.">") |
569 | 373 let repkeep= &report |
374 set report=10 | |
557 | 375 |
1702 | 376 if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-' |
377 redraw! | |
2034 | 378 echohl WarningMsg | echo '***warning*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"' |
1702 | 379 " call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"') |
380 return | |
381 endif | |
382 | |
527 | 383 " sanity checks |
819 | 384 if !executable(g:tar_cmd) |
1125 | 385 redraw! |
19099 | 386 " call Decho('***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system') |
569 | 387 let &report= repkeep |
527 | 388 " call Dret("tar#Write") |
389 return | |
390 endif | |
391 if !exists("*mkdir") | |
1125 | 392 redraw! |
19099 | 393 " call Decho("***error*** (tar#Write) sorry, mkdir() doesn't work on your system") |
557 | 394 echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None |
569 | 395 let &report= repkeep |
527 | 396 " call Dret("tar#Write") |
397 return | |
398 endif | |
399 | |
400 let curdir= getcwd() | |
401 let tmpdir= tempname() | |
402 " call Decho("orig tempname<".tmpdir.">") | |
403 if tmpdir =~ '\.' | |
404 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | |
405 endif | |
406 " call Decho("tmpdir<".tmpdir.">") | |
407 call mkdir(tmpdir,"p") | |
408 | |
409 " attempt to change to the indicated directory | |
410 try | |
1624 | 411 exe "cd ".fnameescape(tmpdir) |
527 | 412 catch /^Vim\%((\a\+)\)\=:E344/ |
1125 | 413 redraw! |
19099 | 414 " call Decho("***error*** (tar#Write) cannot cd to temporary directory") |
557 | 415 echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None |
569 | 416 let &report= repkeep |
527 | 417 " call Dret("tar#Write") |
418 return | |
419 endtry | |
420 " call Decho("current directory now: ".getcwd()) | |
446 | 421 |
557 | 422 " place temporary files under .../_ZIPVIM_/ |
423 if isdirectory("_ZIPVIM_") | |
424 call s:Rmdir("_ZIPVIM_") | |
527 | 425 endif |
557 | 426 call mkdir("_ZIPVIM_") |
427 cd _ZIPVIM_ | |
527 | 428 " call Decho("current directory now: ".getcwd()) |
429 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
430 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
|
431 let fname = substitute(b:tarfile,'tarfile:.\{-}::\(.*\)$','\1','') |
557 | 432 |
433 " handle compressed archives | |
2034 | 434 if tarfile =~# '\.bz2' |
435 call system("bzip2 -d -- ".shellescape(tarfile,0)) | |
436 let tarfile = substitute(tarfile,'\.bz2','','e') | |
437 let compress= "bzip2 -- ".shellescape(tarfile,0) | |
438 " call Decho("compress<".compress.">") | |
439 elseif tarfile =~# '\.gz' | |
19099 | 440 call system("gzip -d -- ".shellescape(tarfile,0)) |
557 | 441 let tarfile = substitute(tarfile,'\.gz','','e') |
2034 | 442 let compress= "gzip -- ".shellescape(tarfile,0) |
443 " call Decho("compress<".compress.">") | |
557 | 444 elseif tarfile =~# '\.tgz' |
19099 | 445 call system("gzip -d -- ".shellescape(tarfile,0)) |
557 | 446 let tarfile = substitute(tarfile,'\.tgz','.tar','e') |
2034 | 447 let compress= "gzip -- ".shellescape(tarfile,0) |
557 | 448 let tgz = 1 |
1702 | 449 " call Decho("compress<".compress.">") |
2426 | 450 elseif tarfile =~# '\.xz' |
451 call system("xz -d -- ".shellescape(tarfile,0)) | |
452 let tarfile = substitute(tarfile,'\.xz','','e') | |
453 let compress= "xz -- ".shellescape(tarfile,0) | |
454 " call Decho("compress<".compress.">") | |
455 elseif tarfile =~# '\.lzma' | |
456 call system("lzma -d -- ".shellescape(tarfile,0)) | |
457 let tarfile = substitute(tarfile,'\.lzma','','e') | |
458 let compress= "lzma -- ".shellescape(tarfile,0) | |
459 " call Decho("compress<".compress.">") | |
527 | 460 endif |
1624 | 461 " call Decho("tarfile<".tarfile.">") |
527 | 462 |
463 if v:shell_error != 0 | |
1125 | 464 redraw! |
19099 | 465 " call Decho("***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname) |
557 | 466 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None |
527 | 467 else |
557 | 468 |
469 " call Decho("tarfile<".tarfile."> fname<".fname.">") | |
470 | |
624 | 471 if fname =~ '/' |
472 let dirpath = substitute(fname,'/[^/]\+$','','e') | |
4339 | 473 if has("win32unix") && executable("cygpath") |
2034 | 474 let dirpath = substitute(system("cygpath ".shellescape(dirpath, 0)),'\n','','e') |
624 | 475 endif |
476 call mkdir(dirpath,"p") | |
477 endif | |
557 | 478 if tarfile !~ '/' |
479 let tarfile= curdir.'/'.tarfile | |
480 endif | |
1702 | 481 if tarfile =~ '^\s*-' |
482 " A file name starting with a dash may be taken as an option. Prepend ./ to avoid that. | |
483 let tarfile = substitute(tarfile, '-', './-', '') | |
484 endif | |
557 | 485 " call Decho("tarfile<".tarfile."> fname<".fname.">") |
486 | |
1702 | 487 if exists("g:tar_secure") |
488 let tar_secure= " -- " | |
489 else | |
490 let tar_secure= " " | |
491 endif | |
1624 | 492 exe "w! ".fnameescape(fname) |
4339 | 493 if has("win32unix") && executable("cygpath") |
2034 | 494 let tarfile = substitute(system("cygpath ".shellescape(tarfile,0)),'\n','','e') |
557 | 495 endif |
496 | |
497 " delete old file from tarfile | |
19099 | 498 " call Decho("system(".g:tar_cmd." ".g:tar_delfile." ".shellescape(tarfile,0)." -- ".shellescape(fname,0).")") |
499 call system(g:tar_cmd." ".g:tar_delfile." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) | |
557 | 500 if v:shell_error != 0 |
1125 | 501 redraw! |
19099 | 502 " call Decho("***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname)) |
1624 | 503 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
557 | 504 else |
505 | |
506 " update tarfile with new file | |
2034 | 507 " call Decho(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) |
508 call system(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) | |
557 | 509 if v:shell_error != 0 |
1125 | 510 redraw! |
19099 | 511 " call Decho("***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname)) |
1624 | 512 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
557 | 513 elseif exists("compress") |
514 " call Decho("call system(".compress.")") | |
515 call system(compress) | |
516 if exists("tgz") | |
517 " call Decho("rename(".tarfile.".gz,".substitute(tarfile,'\.tar$','.tgz','e').")") | |
518 call rename(tarfile.".gz",substitute(tarfile,'\.tar$','.tgz','e')) | |
519 endif | |
520 endif | |
521 endif | |
522 | |
523 " support writing tarfiles across a network | |
524 if s:tblfile_{winnr()} =~ '^\a\+://' | |
525 " call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">") | |
526 let tblfile= s:tblfile_{winnr()} | |
19099 | 527 1split|noswapfile enew |
2034 | 528 let binkeep= &l:binary |
557 | 529 let eikeep = &ei |
530 set binary ei=all | |
19099 | 531 exe "noswapfile e! ".fnameescape(tarfile) |
557 | 532 call netrw#NetWrite(tblfile) |
2034 | 533 let &ei = eikeep |
534 let &l:binary = binkeep | |
557 | 535 q! |
536 unlet s:tblfile_{winnr()} | |
537 endif | |
527 | 538 endif |
539 | |
540 " cleanup and restore current directory | |
541 cd .. | |
557 | 542 call s:Rmdir("_ZIPVIM_") |
1668 | 543 exe "cd ".fnameescape(curdir) |
527 | 544 setlocal nomod |
545 | |
569 | 546 let &report= repkeep |
527 | 547 " call Dret("tar#Write") |
548 endfun | |
549 | |
550 " --------------------------------------------------------------------- | |
4339 | 551 " tar#Diff: {{{2 |
552 fun! tar#Diff(userfname,fname) | |
553 " call Dfunc("tar#Diff(userfname<".a:userfname."> fname<".a:fname.")") | |
554 let fname= a:fname | |
555 if a:userfname != "" | |
556 let fname= a:userfname | |
557 endif | |
558 if filereadable(fname) | |
559 " sets current file (from tarball) for diff'ing | |
560 " splits window vertically | |
561 " opens original file, sets it for diff'ing | |
562 " sets up b:tardiff_otherbuf variables so each buffer knows about the other (for closing purposes) | |
563 diffthis | |
564 wincmd v | |
19099 | 565 exe "noswapfile e ".fnameescape(fname) |
4339 | 566 diffthis |
567 else | |
568 redraw! | |
569 echo "***warning*** unable to read file<".fname.">" | |
570 endif | |
571 " call Dret("tar#Diff") | |
572 endfun | |
573 | |
574 " --------------------------------------------------------------------- | |
19099 | 575 " tar#Extract: extract a file from a (possibly compressed) tar archive {{{2 |
576 fun! tar#Extract() | |
577 " call Dfunc("tar#Extract()") | |
578 | |
579 let repkeep= &report | |
580 set report=10 | |
581 let fname= getline(".") | |
582 " call Decho("fname<".fname.">") | |
583 | |
584 if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' | |
585 redraw! | |
586 echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"' | |
587 " call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') | |
588 return | |
589 endif | |
590 | |
591 " sanity check | |
592 if fname =~ '^"' | |
593 let &report= repkeep | |
594 " call Dret("TarBrowseSelect") | |
595 return | |
596 endif | |
597 | |
598 let tarball = expand("%") | |
599 " call Decho("tarball<".tarball.">") | |
600 let tarbase = substitute(tarball,'\..*$','','') | |
601 " call Decho("tarbase<".tarbase.">") | |
602 | |
603 let extractcmd= netrw#WinPath(g:tar_extractcmd) | |
604 if filereadable(tarbase.".tar") | |
605 " call Decho("system(".extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname).")") | |
606 call system(extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname)) | |
607 if v:shell_error != 0 | |
608 echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar ".fname.": failed!" | echohl NONE | |
609 " call Decho("***error*** ".extractcmd." ".tarbase.".tar ".fname.": failed!") | |
610 else | |
611 echo "***note*** successfully extracted ".fname | |
612 endif | |
613 | |
614 elseif filereadable(tarbase.".tgz") | |
615 let extractcmd= substitute(extractcmd,"-","-z","") | |
616 " call Decho("system(".extractcmd." ".shellescape(tarbase).".tgz ".shellescape(fname).")") | |
617 call system(extractcmd." ".shellescape(tarbase).".tgz ".shellescape(fname)) | |
618 if v:shell_error != 0 | |
619 echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tgz ".fname.": failed!" | echohl NONE | |
620 " call Decho("***error*** ".extractcmd."t ".tarbase.".tgz ".fname.": failed!") | |
621 else | |
622 echo "***note*** successfully extracted ".fname | |
623 endif | |
624 | |
625 elseif filereadable(tarbase.".tar.gz") | |
626 let extractcmd= substitute(extractcmd,"-","-z","") | |
627 " call Decho("system(".extractcmd." ".shellescape(tarbase).".tar.gz ".shellescape(fname).")") | |
628 call system(extractcmd." ".shellescape(tarbase).".tar.gz ".shellescape(fname)) | |
629 if v:shell_error != 0 | |
630 echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.gz ".fname.": failed!" | echohl NONE | |
631 " call Decho("***error*** ".extractcmd." ".tarbase.".tar.gz ".fname.": failed!") | |
632 else | |
633 echo "***note*** successfully extracted ".fname | |
634 endif | |
635 | |
636 elseif filereadable(tarbase.".tbz") | |
637 let extractcmd= substitute(extractcmd,"-","-j","") | |
638 " call Decho("system(".extractcmd." ".shellescape(tarbase).".tbz ".shellescape(fname).")") | |
639 call system(extractcmd." ".shellescape(tarbase).".tbz ".shellescape(fname)) | |
640 if v:shell_error != 0 | |
641 echohl Error | echo "***error*** ".extractcmd."j ".tarbase.".tbz ".fname.": failed!" | echohl NONE | |
642 " call Decho("***error*** ".extractcmd."j ".tarbase.".tbz ".fname.": failed!") | |
643 else | |
644 echo "***note*** successfully extracted ".fname | |
645 endif | |
646 | |
647 elseif filereadable(tarbase.".tar.bz2") | |
648 let extractcmd= substitute(extractcmd,"-","-j","") | |
649 " call Decho("system(".extractcmd." ".shellescape(tarbase).".tar.bz2 ".shellescape(fname).")") | |
650 call system(extractcmd." ".shellescape(tarbase).".tar.bz2 ".shellescape(fname)) | |
651 if v:shell_error != 0 | |
652 echohl Error | echo "***error*** ".extractcmd."j ".tarbase.".tar.bz2 ".fname.": failed!" | echohl NONE | |
653 " call Decho("***error*** ".extractcmd."j ".tarbase.".tar.bz2 ".fname.": failed!") | |
654 else | |
655 echo "***note*** successfully extracted ".fname | |
656 endif | |
657 | |
658 elseif filereadable(tarbase.".txz") | |
659 let extractcmd= substitute(extractcmd,"-","-J","") | |
660 " call Decho("system(".extractcmd." ".shellescape(tarbase).".txz ".shellescape(fname).")") | |
661 call system(extractcmd." ".shellescape(tarbase).".txz ".shellescape(fname)) | |
662 if v:shell_error != 0 | |
663 echohl Error | echo "***error*** ".extractcmd." ".tarbase.".txz ".fname.": failed!" | echohl NONE | |
664 " call Decho("***error*** ".extractcmd." ".tarbase.".txz ".fname.": failed!") | |
665 else | |
666 echo "***note*** successfully extracted ".fname | |
667 endif | |
668 | |
669 elseif filereadable(tarbase.".tar.xz") | |
670 let extractcmd= substitute(extractcmd,"-","-J","") | |
671 " call Decho("system(".extractcmd." ".shellescape(tarbase).".tar.xz ".shellescape(fname).")") | |
672 call system(extractcmd." ".shellescape(tarbase).".tar.xz ".shellescape(fname)) | |
673 if v:shell_error != 0 | |
674 echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.xz ".fname.": failed!" | echohl NONE | |
675 " call Decho("***error*** ".extractcmd." ".tarbase.".tar.xz ".fname.": failed!") | |
676 else | |
677 echo "***note*** successfully extracted ".fname | |
678 endif | |
679 endif | |
680 | |
681 " restore option | |
682 let &report= repkeep | |
683 | |
684 " call Dret("tar#Extract") | |
685 endfun | |
686 | |
687 " --------------------------------------------------------------------- | |
2034 | 688 " s:Rmdir: {{{2 |
527 | 689 fun! s:Rmdir(fname) |
690 " call Dfunc("Rmdir(fname<".a:fname.">)") | |
691 if has("unix") | |
2034 | 692 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
527 | 693 elseif has("win32") || has("win95") || has("win64") || has("win16") |
694 if &shell =~? "sh$" | |
2034 | 695 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
527 | 696 else |
2034 | 697 call system("del /S ".shellescape(a:fname,0)) |
527 | 698 endif |
699 endif | |
700 " call Dret("Rmdir") | |
701 endfun | |
702 | |
1624 | 703 " --------------------------------------------------------------------- |
2034 | 704 " tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2 |
705 fun! tar#Vimuntar(...) | |
706 " call Dfunc("tar#Vimuntar() a:0=".a:0." a:1<".(exists("a:1")? a:1 : "-n/a-").">") | |
707 let tarball = expand("%") | |
708 " call Decho("tarball<".tarball.">") | |
709 let tarbase = substitute(tarball,'\..*$','','') | |
710 " call Decho("tarbase<".tarbase.">") | |
711 let tarhome = expand("%:p") | |
712 if has("win32") || has("win95") || has("win64") || has("win16") | |
713 let tarhome= substitute(tarhome,'\\','/','g') | |
714 endif | |
715 let tarhome= substitute(tarhome,'/[^/]*$','','') | |
716 " call Decho("tarhome<".tarhome.">") | |
717 let tartail = expand("%:t") | |
718 " call Decho("tartail<".tartail.">") | |
719 let curdir = getcwd() | |
720 " call Decho("curdir <".curdir.">") | |
721 " set up vimhome | |
722 if a:0 > 0 && a:1 != "" | |
723 let vimhome= a:1 | |
724 else | |
725 let vimhome= vimball#VimballHome() | |
726 endif | |
727 " call Decho("vimhome<".vimhome.">") | |
728 | |
729 " call Decho("curdir<".curdir."> vimhome<".vimhome.">") | |
730 if simplify(curdir) != simplify(vimhome) | |
731 " copy (possibly compressed) tarball to .vim/vimfiles | |
732 " call Decho(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
733 call system(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
734 " call Decho("exe cd ".fnameescape(vimhome)) | |
735 exe "cd ".fnameescape(vimhome) | |
736 endif | |
737 " call Decho("getcwd<".getcwd().">") | |
738 | |
739 " if necessary, decompress the tarball; then, extract it | |
740 if tartail =~ '\.tgz' | |
19099 | 741 if executable("gunzip") |
2034 | 742 silent exe "!gunzip ".shellescape(tartail) |
743 elseif executable("gzip") | |
744 silent exe "!gzip -d ".shellescape(tartail) | |
1668 | 745 else |
2034 | 746 echoerr "unable to decompress<".tartail."> on this sytem" |
747 if simplify(curdir) != simplify(tarhome) | |
748 " remove decompressed tarball, restore directory | |
749 " call Decho("delete(".tartail.".tar)") | |
750 call delete(tartail.".tar") | |
751 " call Decho("exe cd ".fnameescape(curdir)) | |
752 exe "cd ".fnameescape(curdir) | |
753 endif | |
754 " call Dret("tar#Vimuntar") | |
755 return | |
1668 | 756 endif |
1624 | 757 else |
2034 | 758 call vimball#Decompress(tartail,0) |
1624 | 759 endif |
2034 | 760 let extractcmd= netrw#WinPath(g:tar_extractcmd) |
761 " call Decho("system(".extractcmd." ".shellescape(tarbase.".tar").")") | |
762 call system(extractcmd." ".shellescape(tarbase.".tar")) | |
763 | |
764 " set up help | |
765 if filereadable("doc/".tarbase.".txt") | |
766 " call Decho("exe helptags ".getcwd()."/doc") | |
767 exe "helptags ".getcwd()."/doc" | |
768 endif | |
769 | |
770 if simplify(tarhome) != simplify(vimhome) | |
771 " remove decompressed tarball, restore directory | |
772 call delete(vimhome."/".tarbase.".tar") | |
773 exe "cd ".fnameescape(curdir) | |
774 endif | |
775 | |
776 " call Dret("tar#Vimuntar") | |
1624 | 777 endfun |
778 | |
2034 | 779 " ===================================================================== |
557 | 780 " Modelines And Restoration: {{{1 |
781 let &cpo= s:keepcpo | |
782 unlet s:keepcpo | |
1624 | 783 " vim:ts=8 fdm=marker |