1" tar.vim: Handles browsing tarfiles 2" AUTOLOAD PORTION 3" Date: Apr 17, 2013 4" Version: 29 5" Maintainer: Charles E Campbell <[email protected]> 6" License: Vim License (see vim's :help license) 7" 8" Contains many ideas from Michael Toren's <tar.vim> 9" 10" Copyright: Copyright (C) 2005-2011 Charles E. Campbell {{{1 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, 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. 19" call inputsave()|call input("Press <cr> to continue")|call inputrestore() 20" --------------------------------------------------------------------- 21" Load Once: {{{1 22if &cp || exists("g:loaded_tar") 23 finish 24endif 25let g:loaded_tar= "v29" 26if v:version < 702 27 echohl WarningMsg 28 echo "***warning*** this version of tar needs vim 7.2" 29 echohl Normal 30 finish 31endif 32let s:keepcpo= &cpo 33set cpo&vim 34"DechoTabOn 35"call Decho("loading autoload/tar.vim") 36 37" --------------------------------------------------------------------- 38" Default Settings: {{{1 39if !exists("g:tar_browseoptions") 40 let g:tar_browseoptions= "Ptf" 41endif 42if !exists("g:tar_readoptions") 43 let g:tar_readoptions= "OPxf" 44endif 45if !exists("g:tar_cmd") 46 let g:tar_cmd= "tar" 47endif 48if !exists("g:tar_writeoptions") 49 let g:tar_writeoptions= "uf" 50endif 51if !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 61endif 62if !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 77endif 78if !exists("g:tar_extractcmd") 79 let g:tar_extractcmd= "tar -xf" 80endif 81 82" set up shell quoting character 83if !exists("g:tar_shq") 84 if exists("+shq") && exists("&shq") && &shq != "" 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 93 let g:tar_shq= "'" 94 endif 95" call Decho("g:tar_shq<".g:tar_shq.">") 96endif 97 98" ---------------- 99" Functions: {{{1 100" ---------------- 101 102" --------------------------------------------------------------------- 103" tar#Browse: {{{2 104fun! tar#Browse(tarfile) 105" call Dfunc("tar#Browse(tarfile<".a:tarfile.">)") 106 let repkeep= &report 107 set report=10 108 109 " sanity checks 110 if !executable(g:tar_cmd) 111 redraw! 112 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' 113 let &report= repkeep 114" call Dret("tar#Browse") 115 return 116 endif 117 if !filereadable(a:tarfile) 118" call Decho('a:tarfile<'.a:tarfile.'> not filereadable') 119 if a:tarfile !~# '^\a\+://' 120 " if its an url, don't complain, let url-handlers such as vim do its thing 121 redraw! 122 echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None 123 endif 124 let &report= repkeep 125" call Dret("tar#Browse : file<".a:tarfile."> not readable") 126 return 127 endif 128 if &ma != 1 129 set ma 130 endif 131 let b:tarfile= a:tarfile 132 133 setlocal noswapfile 134 setlocal buftype=nofile 135 setlocal bufhidden=hide 136 setlocal nobuflisted 137 setlocal nowrap 138 set ft=tar 139 140 " give header 141" call Decho("printing header") 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') 146 keepj $put ='' 147 keepj sil! 0d 148 keepj $ 149 150 let tarfile= a:tarfile 151 if has("win32unix") && executable("cygpath") 152 " assuming cygwin 153 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') 154 endif 155 let curlast= line("$") 156 if tarfile =~# '\.\(gz\|tgz\)$' 157" call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") 158 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " 159 elseif tarfile =~# '\.lrp' 160" call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") 161 exe "sil! r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - " 162 elseif tarfile =~# '\.\(bz2\|tbz\|tb2\)$' 163" call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") 164 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " 165 elseif tarfile =~# '\.\(lzma\|tlz\)$' 166" call Decho("3: exe silent r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") 167 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " 168 elseif tarfile =~# '\.\(xz\|txz\)$' 169" call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") 170 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " 171 else 172 if tarfile =~ '^\s*-' 173 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. 174 let tarfile = substitute(tarfile, '-', './-', '') 175 endif 176" call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,0)) 177 exe "sil! r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,1) 178 endif 179 if v:shell_error != 0 180 redraw! 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 185 if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)') 186 redraw! 187 echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None 188 keepj sil! %d 189 let eikeep= &ei 190 set ei=BufReadCmd,FileReadCmd 191 exe "r ".fnameescape(a:tarfile) 192 let &ei= eikeep 193 keepj sil! 1d 194" call Dret("tar#Browse : a:tarfile<".a:tarfile.">") 195 return 196 endif 197 198 setlocal noma nomod ro 199 noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr> 200 201 let &report= repkeep 202" call Dret("tar#Browse : b:tarfile<".b:tarfile.">") 203endfun 204 205" --------------------------------------------------------------------- 206" TarBrowseSelect: {{{2 207fun! s:TarBrowseSelect() 208" call Dfunc("TarBrowseSelect() b:tarfile<".b:tarfile."> curfile<".expand("%").">") 209 let repkeep= &report 210 set report=10 211 let fname= getline(".") 212" call Decho("fname<".fname.">") 213 214 if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' 215 redraw! 216 echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"' 217" call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') 218 return 219 endif 220 221 " sanity check 222 if fname =~ '^"' 223 let &report= repkeep 224" call Dret("TarBrowseSelect") 225 return 226 endif 227 228 " about to make a new window, need to use b:tarfile 229 let tarfile= b:tarfile 230 let curfile= expand("%") 231 if has("win32unix") && executable("cygpath") 232 " assuming cygwin 233 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') 234 endif 235 236 new 237 if !exists("g:tar_nomax") || g:tar_nomax == 0 238 wincmd _ 239 endif 240 let s:tblfile_{winnr()}= curfile 241 call tar#Read("tarfile:".tarfile.'::'.fname,1) 242 filetype detect 243 set nomod 244 exe 'com! -buffer -nargs=? -complete=file TarDiff :call tar#Diff(<q-args>,"'.fnameescape(fname).'")' 245 246 let &report= repkeep 247" call Dret("TarBrowseSelect : s:tblfile_".winnr()."<".s:tblfile_{winnr()}.">") 248endfun 249 250" --------------------------------------------------------------------- 251" tar#Read: {{{2 252fun! tar#Read(fname,mode) 253" call Dfunc("tar#Read(fname<".a:fname.">,mode=".a:mode.")") 254 let repkeep= &report 255 set report=10 256 let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','') 257 let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','') 258 if has("win32unix") && executable("cygpath") 259 " assuming cygwin 260 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') 261 endif 262" call Decho("tarfile<".tarfile.">") 263" call Decho("fname<".fname.">") 264 265 if fname =~ '\.bz2$' && executable("bzcat") 266 let decmp= "|bzcat" 267 let doro = 1 268 elseif fname =~ '\.gz$' && executable("zcat") 269 let decmp= "|zcat" 270 let doro = 1 271 elseif fname =~ '\.lzma$' && executable("lzcat") 272 let decmp= "|lzcat" 273 let doro = 1 274 elseif fname =~ '\.xz$' && executable("xzcat") 275 let decmp= "|xzcat" 276 let doro = 1 277 else 278 let decmp="" 279 let doro = 0 280 if fname =~ '\.bz2$\|\.gz$\|\.lzma$\|\.xz$\|\.zip$\|\.Z$' 281 setlocal bin 282 endif 283 endif 284 285 if exists("g:tar_secure") 286 let tar_secure= " -- " 287 else 288 let tar_secure= " " 289 endif 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) 292 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp 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)) 295 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp 296 elseif tarfile =~# '\.lrp$' 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) 298 exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp 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) 301 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp 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) 304 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp 305 else 306 if tarfile =~ '^\s*-' 307 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. 308 let tarfile = substitute(tarfile, '-', './-', '') 309 endif 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 312 endif 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 319 let b:tarfile= a:fname 320 exe "file tarfile::".fnameescape(fname) 321 322 " cleanup 323 keepj sil! 0d 324 set nomod 325 326 let &report= repkeep 327" call Dret("tar#Read : b:tarfile<".b:tarfile.">") 328endfun 329 330" --------------------------------------------------------------------- 331" tar#Write: {{{2 332fun! tar#Write(fname) 333" call Dfunc("tar#Write(fname<".a:fname.">) b:tarfile<".b:tarfile."> tblfile_".winnr()."<".s:tblfile_{winnr()}.">") 334 let repkeep= &report 335 set report=10 336 337 if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-' 338 redraw! 339 echohl WarningMsg | echo '***warning*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"' 340" call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"') 341 return 342 endif 343 344 " sanity checks 345 if !executable(g:tar_cmd) 346 redraw! 347 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' 348 let &report= repkeep 349" call Dret("tar#Write") 350 return 351 endif 352 if !exists("*mkdir") 353 redraw! 354 echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None 355 let &report= repkeep 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 371 exe "cd ".fnameescape(tmpdir) 372 catch /^Vim\%((\a\+)\)\=:E344/ 373 redraw! 374 echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None 375 let &report= repkeep 376" call Dret("tar#Write") 377 return 378 endtry 379" call Decho("current directory now: ".getcwd()) 380 381 " place temporary files under .../_ZIPVIM_/ 382 if isdirectory("_ZIPVIM_") 383 call s:Rmdir("_ZIPVIM_") 384 endif 385 call mkdir("_ZIPVIM_") 386 cd _ZIPVIM_ 387" call Decho("current directory now: ".getcwd()) 388 389 let tarfile = substitute(b:tarfile,'tarfile:\(.\{-}\)::.*$','\1','') 390 let fname = substitute(b:tarfile,'tarfile:.\{-}::\(.*\)$','\1','') 391 392 " handle compressed archives 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)) 400 let tarfile = substitute(tarfile,'\.gz','','e') 401 let compress= "gzip -- ".shellescape(tarfile,0) 402" call Decho("compress<".compress.">") 403 elseif tarfile =~# '\.tgz' 404 call system("gzip -d -- ".shellescape(tarfile,0)) 405 let tarfile = substitute(tarfile,'\.tgz','.tar','e') 406 let compress= "gzip -- ".shellescape(tarfile,0) 407 let tgz = 1 408" call Decho("compress<".compress.">") 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.">") 419 endif 420" call Decho("tarfile<".tarfile.">") 421 422 if v:shell_error != 0 423 redraw! 424 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None 425 else 426 427" call Decho("tarfile<".tarfile."> fname<".fname.">") 428 429 if fname =~ '/' 430 let dirpath = substitute(fname,'/[^/]\+$','','e') 431 if has("win32unix") && executable("cygpath") 432 let dirpath = substitute(system("cygpath ".shellescape(dirpath, 0)),'\n','','e') 433 endif 434 call mkdir(dirpath,"p") 435 endif 436 if tarfile !~ '/' 437 let tarfile= curdir.'/'.tarfile 438 endif 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 443" call Decho("tarfile<".tarfile."> fname<".fname.">") 444 445 if exists("g:tar_secure") 446 let tar_secure= " -- " 447 else 448 let tar_secure= " " 449 endif 450 exe "w! ".fnameescape(fname) 451 if has("win32unix") && executable("cygpath") 452 let tarfile = substitute(system("cygpath ".shellescape(tarfile,0)),'\n','','e') 453 endif 454 455 " delete old file from tarfile 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)) 458 if v:shell_error != 0 459 redraw! 460 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None 461 else 462 463 " update tarfile with new file 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)) 466 if v:shell_error != 0 467 redraw! 468 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None 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 484 let binkeep= &l:binary 485 let eikeep = &ei 486 set binary ei=all 487 exe "e! ".fnameescape(tarfile) 488 call netrw#NetWrite(tblfile) 489 let &ei = eikeep 490 let &l:binary = binkeep 491 q! 492 unlet s:tblfile_{winnr()} 493 endif 494 endif 495 496 " cleanup and restore current directory 497 cd .. 498 call s:Rmdir("_ZIPVIM_") 499 exe "cd ".fnameescape(curdir) 500 setlocal nomod 501 502 let &report= repkeep 503" call Dret("tar#Write") 504endfun 505 506" --------------------------------------------------------------------- 507" tar#Diff: {{{2 508fun! 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") 528endfun 529 530" --------------------------------------------------------------------- 531" s:Rmdir: {{{2 532fun! s:Rmdir(fname) 533" call Dfunc("Rmdir(fname<".a:fname.">)") 534 if has("unix") 535 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) 536 elseif has("win32") || has("win95") || has("win64") || has("win16") 537 if &shell =~? "sh$" 538 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) 539 else 540 call system("del /S ".shellescape(a:fname,0)) 541 endif 542 endif 543" call Dret("Rmdir") 544endfun 545 546" --------------------------------------------------------------------- 547" tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2 548fun! 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) 588 else 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 599 endif 600 else 601 call vimball#Decompress(tartail,0) 602 endif 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") 620endfun 621 622" ===================================================================== 623" Modelines And Restoration: {{{1 624let &cpo= s:keepcpo 625unlet s:keepcpo 626" vim:ts=8 fdm=marker 627