updated for version 7.2a
This commit is contained in:
@ -1,21 +1,21 @@
|
||||
" tar.vim: Handles browsing tarfiles
|
||||
" AUTOLOAD PORTION
|
||||
" Date: Sep 29, 2006
|
||||
" Version: 11
|
||||
" Date: Jun 12, 2008
|
||||
" Version: 16
|
||||
" Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
|
||||
" License: Vim License (see vim's :help license)
|
||||
"
|
||||
" Contains many ideas from Michael Toren's <tar.vim>
|
||||
"
|
||||
" Copyright: Copyright (C) 2005 Charles E. Campbell, Jr. {{{1
|
||||
" Copyright: Copyright (C) 2005-2008 Charles E. Campbell, Jr. {{{1
|
||||
" Permission is hereby granted to use and distribute this code,
|
||||
" with or without modifications, provided that this copyright
|
||||
" notice is copied with it. Like anything else that's free,
|
||||
" tarPlugin.vim is provided *as is* and comes with no warranty
|
||||
" of any kind, either expressed or implied. By using this
|
||||
" plugin, you agree that in no event will the copyright
|
||||
" holder be liable for any damages resulting from the use
|
||||
" of this software.
|
||||
" tar.vim and tarPlugin.vim are provided *as is* and comes
|
||||
" with no warranty of any kind, either expressed or implied.
|
||||
" By using this plugin, you agree that in no event will the
|
||||
" copyright holder be liable for any damages resulting from
|
||||
" the use of this software.
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Load Once: {{{1
|
||||
@ -24,8 +24,11 @@ set cpo&vim
|
||||
if &cp || exists("g:loaded_tar") || v:version < 700
|
||||
finish
|
||||
endif
|
||||
let g:loaded_tar= "v11"
|
||||
let g:loaded_tar= "v16"
|
||||
"call Decho("loading autoload/tar.vim")
|
||||
if v:version < 701 || (v:version == 701 && !has("patch299"))
|
||||
echoerr "(autoload/tar.vim) need vim v7.1 with patchlevel 299"
|
||||
endif
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Default Settings: {{{1
|
||||
@ -41,14 +44,35 @@ endif
|
||||
if !exists("g:tar_writeoptions")
|
||||
let g:tar_writeoptions= "uf"
|
||||
endif
|
||||
if !exists("g:tar_shq")
|
||||
if has("unix")
|
||||
let g:tar_shq= "'"
|
||||
|
||||
if !exists("g:netrw_cygwin")
|
||||
if has("win32") || has("win95") || has("win64") || has("win16")
|
||||
if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
|
||||
let g:netrw_cygwin= 1
|
||||
else
|
||||
let g:netrw_cygwin= 0
|
||||
endif
|
||||
else
|
||||
let g:tar_shq= '"'
|
||||
let g:netrw_cygwin= 0
|
||||
endif
|
||||
endif
|
||||
|
||||
" set up shell quoting character
|
||||
if !exists("g:tar_shq")
|
||||
if exists("&shq") && &shq != ""
|
||||
let g:tar_shq= &shq
|
||||
elseif has("win32") || has("win95") || has("win64") || has("win16")
|
||||
if exists("g:netrw_cygwin") && g:netrw_cygwin
|
||||
let g:tar_shq= "'"
|
||||
else
|
||||
let g:tar_shq= '"'
|
||||
endif
|
||||
else
|
||||
let g:tar_shq= "'"
|
||||
endif
|
||||
" call Decho("g:tar_shq<".g:tar_shq.">")
|
||||
endif
|
||||
|
||||
" ----------------
|
||||
" Functions: {{{1
|
||||
" ----------------
|
||||
@ -95,27 +119,32 @@ fun! tar#Browse(tarfile)
|
||||
|
||||
" give header
|
||||
" call Decho("printing header")
|
||||
exe "$put ='".'\"'." tar.vim version ".g:loaded_tar."'"
|
||||
exe "$put ='".'\"'." Browsing tarfile ".a:tarfile."'"
|
||||
exe "$put ='".'\"'." Select a file with cursor and press ENTER"."'"
|
||||
let lastline= line("$")
|
||||
call setline(lastline+1,'" tar.vim version '.g:loaded_tar)
|
||||
call setline(lastline+2,'" Browsing tarfile '.a:tarfile)
|
||||
call setline(lastline+3,'" Select a file with cursor and press ENTER')
|
||||
$put =''
|
||||
0d
|
||||
$
|
||||
|
||||
let tarfile= a:tarfile
|
||||
if has("win32") && executable("cygpath")
|
||||
" assuming cygwin
|
||||
let tarfile=substitute(system("cygpath -u ".tarfile),'\n$','','e')
|
||||
let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile)),'\n$','','e')
|
||||
endif
|
||||
let curlast= line("$")
|
||||
if tarfile =~# '\.\(gz\|tgz\)$'
|
||||
" call Decho("exe silent r! gzip -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -".g:tar_browseoptions." - ")
|
||||
exe "silent r! gzip -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -".g:tar_browseoptions." - "
|
||||
" call Decho("1: exe silent r! gzip -d -c ".s:Escape(tarfile)." | ".g:tar_cmd." -".g:tar_browseoptions." - ")
|
||||
exe "silent r! gzip -d -c -- ".s:Escape(tarfile)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
||||
elseif tarfile =~# '\.lrp'
|
||||
" call Decho("2: exe silent r! cat -- ".s:Escape(tarfile)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ")
|
||||
exe "silent r! cat -- ".s:Escape(tarfile)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - "
|
||||
elseif tarfile =~# '\.bz2$'
|
||||
" call Decho("exe silent r! bzip2 -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -".g:tar_browseoptions." - ")
|
||||
exe "silent r! bzip2 -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -".g:tar_browseoptions." - "
|
||||
" call Decho("3: exe silent r! bzip2 -d -c ".s:Escape(tarfile)." | ".g:tar_cmd." -".g:tar_browseoptions." - ")
|
||||
exe "silent r! bzip2 -d -c -- ".s:Escape(tarfile)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
||||
else
|
||||
" call Decho("exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".g:tar_shq.tarfile.g:tar_shq)
|
||||
exe "silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".g:tar_shq.tarfile.g:tar_shq
|
||||
" call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".s:Escape(tarfile))
|
||||
exe "silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".s:Escape(tarfile)
|
||||
endif
|
||||
if v:shell_error != 0
|
||||
redraw!
|
||||
@ -166,13 +195,15 @@ fun! s:TarBrowseSelect()
|
||||
let curfile= expand("%")
|
||||
if has("win32") && executable("cygpath")
|
||||
" assuming cygwin
|
||||
let tarfile=substitute(system("cygpath -u ".tarfile),'\n$','','e')
|
||||
let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile)),'\n$','','e')
|
||||
endif
|
||||
|
||||
new
|
||||
wincmd _
|
||||
if !exists("g:tar_nomax") || g:tar_nomax == 0
|
||||
wincmd _
|
||||
endif
|
||||
let s:tblfile_{winnr()}= curfile
|
||||
call tar#Read("tarfile:".tarfile.':'.fname,1)
|
||||
call tar#Read("tarfile:".tarfile.'::'.fname,1)
|
||||
filetype detect
|
||||
|
||||
let &report= repkeep
|
||||
@ -185,27 +216,50 @@ fun! tar#Read(fname,mode)
|
||||
" call Dfunc("tar#Read(fname<".a:fname.">,mode=".a:mode.")")
|
||||
let repkeep= &report
|
||||
set report=10
|
||||
let tarfile = substitute(a:fname,'tarfile:\(.\{-}\):.*$','\1','')
|
||||
let fname = substitute(a:fname,'tarfile:.\{-}:\(.*\)$','\1','')
|
||||
let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','')
|
||||
let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','')
|
||||
if has("win32") && executable("cygpath")
|
||||
" assuming cygwin
|
||||
let tarfile=substitute(system("cygpath -u ".tarfile),'\n$','','e')
|
||||
let tarfile=substitute(system("cygpath -u ".s:Escape(tarfile)),'\n$','','e')
|
||||
endif
|
||||
" call Decho("tarfile<".tarfile.">")
|
||||
" call Decho("fname<".fname.">")
|
||||
|
||||
if tarfile =~# '\.\(gz\|tgz\)$'
|
||||
" call Decho("exe silent r! gzip -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -OPxf - '".fname."'")
|
||||
exe "silent r! gzip -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -".g:tar_readoptions." - '".fname."'"
|
||||
elseif tarfile =~# '\.bz2$'
|
||||
" call Decho("exe silent r! bzip2 -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -".g:tar_readoptions." - '".fname."'")
|
||||
exe "silent r! bzip2 -d -c ".g:tar_shq.tarfile.g:tar_shq."| ".g:tar_cmd." -".g:tar_readoptions." - '".fname."'"
|
||||
if fname =~ '\.gz$' && executable("zcat")
|
||||
let decmp= "|zcat"
|
||||
let doro = 1
|
||||
elseif fname =~ '\.bz2$' && executable("bzcat")
|
||||
let decmp= "|bzcat"
|
||||
let doro = 1
|
||||
else
|
||||
" call Decho("exe silent r! ".g:tar_cmd." -".g:tar_readoptions." ".g:tar_shq.tarfile.g:tar_shq." ".g:tar_shq.fname.g:tar_shq)
|
||||
exe "silent r! ".g:tar_cmd." -".g:tar_readoptions." ".g:tar_shq.tarfile.g:tar_shq." ".g:tar_shq.fname.g:tar_shq
|
||||
let decmp=""
|
||||
let doro = 0
|
||||
if fname =~ '\.gz$\|\.bz2$\|\.Z$\|\.zip$'
|
||||
setlocal bin
|
||||
endif
|
||||
endif
|
||||
|
||||
if tarfile =~# '\.\(gz\|tgz\)$'
|
||||
" call Decho("5: exe silent r! gzip -d -c -- ".s:Escape(tarfile)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.s:Escape(fname))
|
||||
exe "silent r! gzip -d -c -- ".s:Escape(tarfile)."| ".g:tar_cmd." -".g:tar_readoptions." - ".s:Escape(fname).decmp
|
||||
elseif tarfile =~# '\.lrp$'
|
||||
" call Decho("6: exe silent r! cat ".s:Escape(tarfile)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".s:Escape(fname).decmp)
|
||||
exe "silent r! cat -- ".s:Escape(tarfile)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".s:Escape(fname).decmp
|
||||
elseif tarfile =~# '\.bz2$'
|
||||
" call Decho("7: exe silent r! bzip2 -d -c ".s:Escape(tarfile)."| ".g:tar_cmd." -".g:tar_readoptions." - ".s:Escape(fname).decmp)
|
||||
exe "silent r! bzip2 -d -c -- ".s:Escape(tarfile)."| ".g:tar_cmd." -".g:tar_readoptions." - ".s:Escape(fname).decmp
|
||||
else
|
||||
" call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions." -- ".s:Escape(tarfile)." ".s:Escape(fname))
|
||||
exe "silent r! ".g:tar_cmd." -".g:tar_readoptions." ".s:Escape(tarfile)." -- ".s:Escape(fname).decmp
|
||||
endif
|
||||
|
||||
if doro
|
||||
" because the reverse process of compressing changed files back into the tarball is not currently supported
|
||||
setlocal ro
|
||||
endif
|
||||
|
||||
let w:tarfile= a:fname
|
||||
exe "file tarfile:".fname
|
||||
exe "file tarfile::".fname
|
||||
|
||||
" cleanup
|
||||
0d
|
||||
@ -251,7 +305,7 @@ fun! tar#Write(fname)
|
||||
|
||||
" attempt to change to the indicated directory
|
||||
try
|
||||
exe "cd ".escape(tmpdir,' \')
|
||||
exe "cd ".fnameescape(tmpdir)
|
||||
catch /^Vim\%((\a\+)\)\=:E344/
|
||||
redraw!
|
||||
echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None
|
||||
@ -270,24 +324,26 @@ fun! tar#Write(fname)
|
||||
cd _ZIPVIM_
|
||||
" call Decho("current directory now: ".getcwd())
|
||||
|
||||
let tarfile = substitute(w:tarfile,'tarfile:\(.\{-}\):.*$','\1','')
|
||||
let fname = substitute(w:tarfile,'tarfile:.\{-}:\(.*\)$','\1','')
|
||||
let tarfile = substitute(w:tarfile,'tarfile:\(.\{-}\)::.*$','\1','')
|
||||
let fname = substitute(w:tarfile,'tarfile:.\{-}::\(.*\)$','\1','')
|
||||
|
||||
" handle compressed archives
|
||||
if tarfile =~# '\.gz'
|
||||
call system("gzip -d ".tarfile)
|
||||
call system("gzip -d -- ".tarfile)
|
||||
let tarfile = substitute(tarfile,'\.gz','','e')
|
||||
let compress= "gzip '".tarfile."'"
|
||||
let compress= "gzip ".s:Escape(tarfile)
|
||||
elseif tarfile =~# '\.tgz'
|
||||
call system("gzip -d ".tarfile)
|
||||
call system("gzip -d -- ".s:Escape(tarfile))
|
||||
let tarfile = substitute(tarfile,'\.tgz','.tar','e')
|
||||
let compress= "gzip '".tarfile."'"
|
||||
let compress= "gzip -- ".s:Escape(tarfile)
|
||||
let tgz = 1
|
||||
elseif tarfile =~# '\.bz2'
|
||||
call system("bzip2 -d ".tarfile)
|
||||
call system("bzip2 -d -- ".s:Escape(tarfile))
|
||||
let tarfile = substitute(tarfile,'\.bz2','','e')
|
||||
let compress= "bzip2 '".tarfile."'"
|
||||
let compress= "bzip2 -- ".s:Escape(tarfile)
|
||||
endif
|
||||
" call Decho("tarfile<".tarfile.">")
|
||||
" call Decho("compress<".compress.">")
|
||||
|
||||
if v:shell_error != 0
|
||||
redraw!
|
||||
@ -309,26 +365,26 @@ fun! tar#Write(fname)
|
||||
endif
|
||||
" call Decho("tarfile<".tarfile."> fname<".fname.">")
|
||||
|
||||
exe "w! ".fname
|
||||
exe "w! ".fnameescape(fname)
|
||||
if executable("cygpath")
|
||||
let tarfile = substitute(system("cygpath ".tarfile),'\n','','e')
|
||||
let tarfile = substitute(system("cygpath ".s:Escape(tarfile)),'\n','','e')
|
||||
endif
|
||||
|
||||
" delete old file from tarfile
|
||||
" call Decho("tar --delete -f '".tarfile."' '".fname."'")
|
||||
call system("tar --delete -f '".tarfile."' '".fname."'")
|
||||
" call Decho("system(tar --delete -f ".s:Escape(tarfile)." -- ".s:Escape(fname).")")
|
||||
call system("tar --delete -f ".s:Escape(tarfile)." -- ".s:Escape(fname))
|
||||
if v:shell_error != 0
|
||||
redraw!
|
||||
echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None
|
||||
echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None
|
||||
" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
|
||||
else
|
||||
|
||||
" update tarfile with new file
|
||||
" call Decho("tar -".g:tar_writeoptions." '".tarfile."' '".fname."'")
|
||||
call system("tar -".g:tar_writeoptions." '".tarfile."' '".fname."'")
|
||||
" call Decho("tar -".g:tar_writeoptions." ".s:Escape(tarfile)." -- ".s:Escape(fname))
|
||||
call system("tar -".g:tar_writeoptions." ".s:Escape(tarfile)." -- ".s:Escape(fname))
|
||||
if v:shell_error != 0
|
||||
redraw!
|
||||
echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None
|
||||
echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None
|
||||
" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
|
||||
elseif exists("compress")
|
||||
" call Decho("call system(".compress.")")
|
||||
@ -372,19 +428,31 @@ endfun
|
||||
fun! s:Rmdir(fname)
|
||||
" call Dfunc("Rmdir(fname<".a:fname.">)")
|
||||
if has("unix")
|
||||
call system("/bin/rm -rf ".a:fname)
|
||||
call system("/bin/rm -rf -- ".s:Escape(a:fname))
|
||||
elseif has("win32") || has("win95") || has("win64") || has("win16")
|
||||
if &shell =~? "sh$"
|
||||
call system("/bin/rm -rf ".a:fname)
|
||||
call system("/bin/rm -rf -- ".s:Escape(a:fname))
|
||||
else
|
||||
call system("del /S ".a:fname)
|
||||
call system("del /S ".s:Escape(a:fname))
|
||||
endif
|
||||
endif
|
||||
" call Dret("Rmdir")
|
||||
endfun
|
||||
|
||||
" ------------------------------------------------------------------------
|
||||
" ---------------------------------------------------------------------
|
||||
" s:Escape: {{{2
|
||||
fun s:Escape(name)
|
||||
" shellescape() was added by patch 7.0.111
|
||||
if exists("*shellescape")
|
||||
let qnameq= shellescape(a:name)
|
||||
else
|
||||
let qnameq= g:tar_shq . a:name . g:tar_shq
|
||||
endif
|
||||
return qnameq
|
||||
endfun
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Modelines And Restoration: {{{1
|
||||
let &cpo= s:keepcpo
|
||||
unlet s:keepcpo
|
||||
" vim:ts=8 fdm=marker
|
||||
" vim:ts=8 fdm=marker
|
||||
|
||||
Reference in New Issue
Block a user