2025-02-06 21:10:49 +01:00
|
|
|
" tar.vim: Handles browsing tarfiles - AUTOLOAD PORTION
|
|
|
|
" Date: Feb 06, 2025
|
2023-11-14 17:15:17 +01:00
|
|
|
" Version: 32b (with modifications from the Vim Project)
|
2024-02-19 20:37:11 +01:00
|
|
|
" Maintainer: This runtime file is looking for a new maintainer.
|
|
|
|
" Former Maintainer: Charles E Campbell
|
2020-01-09 21:46:04 +01:00
|
|
|
" License: Vim License (see vim's :help license)
|
2005-07-27 21:13:01 +00:00
|
|
|
"
|
2005-11-23 21:25:05 +00:00
|
|
|
" Contains many ideas from Michael Toren's <tar.vim>
|
2005-07-27 21:13:01 +00:00
|
|
|
"
|
2020-01-09 21:46:04 +01:00
|
|
|
" Copyright: Copyright (C) 2005-2017 Charles E. Campbell {{{1
|
2005-11-23 21:25:05 +00:00
|
|
|
" 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,
|
2008-06-24 22:58:06 +00:00
|
|
|
" 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.
|
2005-11-23 21:25:05 +00:00
|
|
|
" ---------------------------------------------------------------------
|
2007-05-05 18:24:42 +00:00
|
|
|
" Load Once: {{{1
|
2010-01-06 20:54:52 +01:00
|
|
|
if &cp || exists("g:loaded_tar")
|
2005-09-14 21:40:12 +00:00
|
|
|
finish
|
|
|
|
endif
|
2024-11-11 22:39:30 +01:00
|
|
|
let g:loaded_tar= "v32b"
|
2010-01-06 20:54:52 +01:00
|
|
|
if v:version < 702
|
|
|
|
echohl WarningMsg
|
|
|
|
echo "***warning*** this version of tar needs vim 7.2"
|
|
|
|
echohl Normal
|
|
|
|
finish
|
2008-06-24 22:58:06 +00:00
|
|
|
endif
|
2010-01-06 20:54:52 +01:00
|
|
|
let s:keepcpo= &cpo
|
|
|
|
set cpo&vim
|
2005-09-14 21:40:12 +00:00
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
2005-11-23 21:25:05 +00:00
|
|
|
" Default Settings: {{{1
|
|
|
|
if !exists("g:tar_browseoptions")
|
|
|
|
let g:tar_browseoptions= "Ptf"
|
|
|
|
endif
|
|
|
|
if !exists("g:tar_readoptions")
|
2024-11-11 22:39:30 +01:00
|
|
|
let g:tar_readoptions= "pPxf"
|
2005-11-23 21:25:05 +00:00
|
|
|
endif
|
2006-04-05 20:41:53 +00:00
|
|
|
if !exists("g:tar_cmd")
|
|
|
|
let g:tar_cmd= "tar"
|
|
|
|
endif
|
2005-11-23 21:25:05 +00:00
|
|
|
if !exists("g:tar_writeoptions")
|
|
|
|
let g:tar_writeoptions= "uf"
|
|
|
|
endif
|
2020-01-09 21:46:04 +01:00
|
|
|
if !exists("g:tar_delfile")
|
|
|
|
let g:tar_delfile="--delete -f"
|
|
|
|
endif
|
2011-06-19 05:09:16 +02:00
|
|
|
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:netrw_cygwin= 0
|
|
|
|
endif
|
|
|
|
endif
|
2010-01-06 20:54:52 +01:00
|
|
|
if !exists("g:tar_copycmd")
|
|
|
|
if !exists("g:netrw_localcopycmd")
|
|
|
|
if has("win32") || has("win95") || has("win64") || has("win16")
|
|
|
|
if g:netrw_cygwin
|
|
|
|
let g:netrw_localcopycmd= "cp"
|
|
|
|
else
|
|
|
|
let g:netrw_localcopycmd= "copy"
|
|
|
|
endif
|
|
|
|
elseif has("unix") || has("macunix")
|
|
|
|
let g:netrw_localcopycmd= "cp"
|
|
|
|
else
|
|
|
|
let g:netrw_localcopycmd= ""
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let g:tar_copycmd= g:netrw_localcopycmd
|
|
|
|
endif
|
|
|
|
if !exists("g:tar_extractcmd")
|
2024-11-11 22:39:30 +01:00
|
|
|
let g:tar_extractcmd= "tar -pxf"
|
2010-01-06 20:54:52 +01:00
|
|
|
endif
|
2008-06-24 22:58:06 +00:00
|
|
|
|
|
|
|
" set up shell quoting character
|
2007-05-05 18:24:42 +00:00
|
|
|
if !exists("g:tar_shq")
|
2013-04-24 18:51:19 +02:00
|
|
|
if exists("+shq") && exists("&shq") && &shq != ""
|
2008-06-24 22:58:06 +00:00
|
|
|
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
|
2007-05-05 18:24:42 +00:00
|
|
|
else
|
2008-06-24 22:58:06 +00:00
|
|
|
let g:tar_shq= "'"
|
2007-05-05 18:24:42 +00:00
|
|
|
endif
|
|
|
|
endif
|
2005-07-27 21:13:01 +00:00
|
|
|
|
2005-11-23 21:25:05 +00:00
|
|
|
" ----------------
|
|
|
|
" Functions: {{{1
|
|
|
|
" ----------------
|
2005-07-27 21:13:01 +00:00
|
|
|
|
2005-11-23 21:25:05 +00:00
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" tar#Browse: {{{2
|
|
|
|
fun! tar#Browse(tarfile)
|
2005-11-28 23:05:55 +00:00
|
|
|
let repkeep= &report
|
|
|
|
set report=10
|
2005-11-23 21:25:05 +00:00
|
|
|
|
|
|
|
" sanity checks
|
2006-04-05 20:41:53 +00:00
|
|
|
if !executable(g:tar_cmd)
|
2007-05-05 18:24:42 +00:00
|
|
|
redraw!
|
2006-04-05 20:41:53 +00:00
|
|
|
echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system'
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-11-23 21:25:05 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
if !filereadable(a:tarfile)
|
|
|
|
if a:tarfile !~# '^\a\+://'
|
2020-01-14 19:29:13 +01:00
|
|
|
" if it's an url, don't complain, let url-handlers such as vim do its thing
|
2007-05-05 18:24:42 +00:00
|
|
|
redraw!
|
2005-11-23 21:25:05 +00:00
|
|
|
echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None
|
|
|
|
endif
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-11-23 21:25:05 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
if &ma != 1
|
|
|
|
set ma
|
|
|
|
endif
|
2010-08-10 21:43:35 +02:00
|
|
|
let b:tarfile= a:tarfile
|
2005-11-23 21:25:05 +00:00
|
|
|
|
|
|
|
setlocal noswapfile
|
|
|
|
setlocal buftype=nofile
|
|
|
|
setlocal bufhidden=hide
|
|
|
|
setlocal nobuflisted
|
|
|
|
setlocal nowrap
|
|
|
|
set ft=tar
|
|
|
|
|
|
|
|
" give header
|
2008-06-24 22:58:06 +00:00
|
|
|
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')
|
2011-06-19 05:09:16 +02:00
|
|
|
keepj $put =''
|
2012-01-20 21:08:56 +01:00
|
|
|
keepj sil! 0d
|
2011-06-19 05:09:16 +02:00
|
|
|
keepj $
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2006-04-05 20:41:53 +00:00
|
|
|
let tarfile= a:tarfile
|
2013-04-24 18:51:19 +02:00
|
|
|
if has("win32unix") && executable("cygpath")
|
2006-04-05 20:41:53 +00:00
|
|
|
" assuming cygwin
|
2010-01-06 20:54:52 +01:00
|
|
|
let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e')
|
2006-04-05 20:41:53 +00:00
|
|
|
endif
|
2006-05-02 22:08:30 +00:00
|
|
|
let curlast= line("$")
|
2020-01-09 21:46:04 +01:00
|
|
|
|
|
|
|
if tarfile =~# '\.\(gz\)$'
|
|
|
|
exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
|
|
|
|
2025-02-06 21:10:49 +01:00
|
|
|
elseif tarfile =~# '\.\(tgz\)$' || tarfile =~# '\.\(tbz\)$' || tarfile =~# '\.\(txz\)$' ||
|
|
|
|
\ tarfile =~# '\.\(tzst\)$' || tarfile =~# '\.\(tlz4\)$'
|
2020-01-09 21:46:04 +01:00
|
|
|
if has("unix") && executable("file")
|
2024-01-08 20:02:14 +01:00
|
|
|
let filekind= system("file ".shellescape(tarfile,1))
|
2020-01-09 21:46:04 +01:00
|
|
|
else
|
|
|
|
let filekind= ""
|
|
|
|
endif
|
|
|
|
|
|
|
|
if filekind =~ "bzip2"
|
|
|
|
exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
|
|
|
elseif filekind =~ "XZ"
|
|
|
|
exe "sil! r! xz -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2020-11-29 14:36:24 +01:00
|
|
|
elseif filekind =~ "Zstandard"
|
|
|
|
exe "sil! r! zstd --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2025-02-06 21:10:49 +01:00
|
|
|
elseif filekind =~ "LZ4"
|
|
|
|
exe "sil! r! lz4 --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2020-01-09 21:46:04 +01:00
|
|
|
else
|
|
|
|
exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
|
|
|
endif
|
|
|
|
|
2008-06-24 22:58:06 +00:00
|
|
|
elseif tarfile =~# '\.lrp'
|
2018-09-08 15:10:34 +02:00
|
|
|
exe "sil! r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - "
|
2012-01-20 21:08:56 +01:00
|
|
|
elseif tarfile =~# '\.\(bz2\|tbz\|tb2\)$'
|
2011-06-19 05:09:16 +02:00
|
|
|
exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2012-01-20 21:08:56 +01:00
|
|
|
elseif tarfile =~# '\.\(lzma\|tlz\)$'
|
2011-06-19 05:09:16 +02:00
|
|
|
exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2010-07-28 18:17:41 +02:00
|
|
|
elseif tarfile =~# '\.\(xz\|txz\)$'
|
2011-06-19 05:09:16 +02:00
|
|
|
exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2024-01-08 20:02:14 +01:00
|
|
|
elseif tarfile =~# '\.\(zst\|tzst\)$'
|
2020-11-29 14:36:24 +01:00
|
|
|
exe "sil! r! zstd --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2025-02-06 21:10:49 +01:00
|
|
|
elseif tarfile =~# '\.\(lz4\|tlz4\)$'
|
|
|
|
exe "sil! r! lz4 --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - "
|
2005-11-23 21:25:05 +00:00
|
|
|
else
|
2008-08-09 17:55:22 +00:00
|
|
|
if tarfile =~ '^\s*-'
|
2010-01-06 20:54:52 +01:00
|
|
|
" A file name starting with a dash is taken as an option. Prepend ./ to avoid that.
|
2008-08-09 17:55:22 +00:00
|
|
|
let tarfile = substitute(tarfile, '-', './-', '')
|
|
|
|
endif
|
2011-06-19 05:09:16 +02:00
|
|
|
exe "sil! r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,1)
|
2006-04-05 20:41:53 +00:00
|
|
|
endif
|
|
|
|
if v:shell_error != 0
|
2007-05-05 18:24:42 +00:00
|
|
|
redraw!
|
2006-05-02 22:08:30 +00:00
|
|
|
echohl WarningMsg | echo "***warning*** (tar#Browse) please check your g:tar_browseoptions<".g:tar_browseoptions.">"
|
|
|
|
return
|
|
|
|
endif
|
runtime(tar): improve the error detection
Do not rely on the fact, that the last line matches warning, error,
inappropriate or unrecognized to determine if an error occurred. It
could also be a file, contains such a keyword.
So make the error detection slightly more strict and only assume an
error occured, if in addition to those 4 keywords, also a space matches
(this assumes the error message contains a space), which luckily on Unix
not many files match by default.
The whole if condition seems however slightly dubious. In case an error
happened, this would probably already be caught in the previous if
statement, since this checks for the return code of the tar program.
There may however be tar implementations, that do not set the exit code
for some kind of error (but print an error message)? But let's keep this
check for now, not many people have noticed this behaviour until now, so
it seems to work reasonably well anyhow.
related: #6425
fixes: #13489
Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-11-05 17:44:05 +01:00
|
|
|
"
|
2023-11-14 17:15:17 +01:00
|
|
|
" The following should not be neccessary, since in case of errors the
|
|
|
|
" previous if statement should have caught the problem (because tar exited
|
|
|
|
" with a non-zero exit code).
|
|
|
|
" if line("$") == curlast || ( line("$") == (curlast + 1) &&
|
|
|
|
" \ getline("$") =~# '\c\<\%(warning\|error\|inappropriate\|unrecognized\)\>' &&
|
|
|
|
" \ getline("$") =~ '\s' )
|
|
|
|
" redraw!
|
|
|
|
" echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None
|
|
|
|
" keepj sil! %d
|
|
|
|
" let eikeep= &ei
|
|
|
|
" set ei=BufReadCmd,FileReadCmd
|
|
|
|
" exe "r ".fnameescape(a:tarfile)
|
|
|
|
" let &ei= eikeep
|
|
|
|
" keepj sil! 1d
|
|
|
|
" call Dret("tar#Browse : a:tarfile<".a:tarfile.">")
|
|
|
|
" return
|
|
|
|
" endif
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2020-01-09 21:46:04 +01:00
|
|
|
" set up maps supported for tar
|
2005-11-23 21:25:05 +00:00
|
|
|
setlocal noma nomod ro
|
2020-01-09 21:46:04 +01:00
|
|
|
noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr>
|
2024-01-08 20:02:14 +01:00
|
|
|
noremap <silent> <buffer> x :call tar#Extract()<cr>
|
2020-01-09 21:46:04 +01:00
|
|
|
if &mouse != ""
|
|
|
|
noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>TarBrowseSelect()<cr>
|
|
|
|
endif
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-09-14 21:40:12 +00:00
|
|
|
endfun
|
2005-07-27 21:13:01 +00:00
|
|
|
|
2005-09-14 21:40:12 +00:00
|
|
|
" ---------------------------------------------------------------------
|
2005-11-23 21:25:05 +00:00
|
|
|
" TarBrowseSelect: {{{2
|
|
|
|
fun! s:TarBrowseSelect()
|
2005-11-28 23:05:55 +00:00
|
|
|
let repkeep= &report
|
|
|
|
set report=10
|
2005-11-23 21:25:05 +00:00
|
|
|
let fname= getline(".")
|
|
|
|
|
2008-08-09 17:55:22 +00:00
|
|
|
if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-'
|
|
|
|
redraw!
|
2010-01-06 20:54:52 +01:00
|
|
|
echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"'
|
2008-08-09 17:55:22 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2005-11-23 21:25:05 +00:00
|
|
|
" sanity check
|
|
|
|
if fname =~ '^"'
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-11-23 21:25:05 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2010-08-10 21:43:35 +02:00
|
|
|
" about to make a new window, need to use b:tarfile
|
|
|
|
let tarfile= b:tarfile
|
2005-11-23 21:25:05 +00:00
|
|
|
let curfile= expand("%")
|
2013-04-24 18:51:19 +02:00
|
|
|
if has("win32unix") && executable("cygpath")
|
2006-04-05 20:41:53 +00:00
|
|
|
" assuming cygwin
|
2010-01-06 20:54:52 +01:00
|
|
|
let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e')
|
2006-04-05 20:41:53 +00:00
|
|
|
endif
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2020-01-09 21:46:04 +01:00
|
|
|
" open a new window (tar#Read will read a file into it)
|
|
|
|
noswapfile new
|
2008-06-24 22:58:06 +00:00
|
|
|
if !exists("g:tar_nomax") || g:tar_nomax == 0
|
|
|
|
wincmd _
|
|
|
|
endif
|
2005-11-23 21:25:05 +00:00
|
|
|
let s:tblfile_{winnr()}= curfile
|
2008-06-24 22:58:06 +00:00
|
|
|
call tar#Read("tarfile:".tarfile.'::'.fname,1)
|
2005-11-23 21:25:05 +00:00
|
|
|
filetype detect
|
2013-04-24 18:51:19 +02:00
|
|
|
set nomod
|
|
|
|
exe 'com! -buffer -nargs=? -complete=file TarDiff :call tar#Diff(<q-args>,"'.fnameescape(fname).'")'
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-11-23 21:25:05 +00:00
|
|
|
endfun
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" tar#Read: {{{2
|
|
|
|
fun! tar#Read(fname,mode)
|
2005-11-28 23:05:55 +00:00
|
|
|
let repkeep= &report
|
|
|
|
set report=10
|
2008-06-24 22:58:06 +00:00
|
|
|
let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','')
|
|
|
|
let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','')
|
2024-11-11 22:39:30 +01:00
|
|
|
|
2025-02-06 21:10:49 +01:00
|
|
|
" changing the directory to the temporary earlier to allow tar to extract the file with permissions intact
|
2024-11-11 22:39:30 +01:00
|
|
|
if !exists("*mkdir")
|
|
|
|
redraw!
|
|
|
|
echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None
|
|
|
|
let &report= repkeep
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let curdir= getcwd()
|
|
|
|
let tmpdir= tempname()
|
|
|
|
let b:curdir= tmpdir
|
|
|
|
let b:tmpdir= curdir
|
|
|
|
if tmpdir =~ '\.'
|
|
|
|
let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
|
|
|
|
endif
|
|
|
|
call mkdir(tmpdir,"p")
|
|
|
|
|
|
|
|
" attempt to change to the indicated directory
|
|
|
|
try
|
|
|
|
exe "cd ".fnameescape(tmpdir)
|
|
|
|
catch /^Vim\%((\a\+)\)\=:E344/
|
|
|
|
redraw!
|
|
|
|
echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None
|
|
|
|
let &report= repkeep
|
|
|
|
return
|
|
|
|
endtry
|
|
|
|
|
|
|
|
" place temporary files under .../_ZIPVIM_/
|
|
|
|
if isdirectory("_ZIPVIM_")
|
|
|
|
call s:Rmdir("_ZIPVIM_")
|
|
|
|
endif
|
|
|
|
call mkdir("_ZIPVIM_")
|
|
|
|
cd _ZIPVIM_
|
|
|
|
|
2013-04-24 18:51:19 +02:00
|
|
|
if has("win32unix") && executable("cygpath")
|
2006-04-05 20:41:53 +00:00
|
|
|
" assuming cygwin
|
2010-01-06 20:54:52 +01:00
|
|
|
let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e')
|
2006-04-05 20:41:53 +00:00
|
|
|
endif
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2010-01-06 20:54:52 +01:00
|
|
|
if fname =~ '\.bz2$' && executable("bzcat")
|
|
|
|
let decmp= "|bzcat"
|
|
|
|
let doro = 1
|
2020-01-09 21:46:04 +01:00
|
|
|
elseif fname =~ '\.t\=gz$' && executable("zcat")
|
2008-06-24 22:58:06 +00:00
|
|
|
let decmp= "|zcat"
|
|
|
|
let doro = 1
|
2010-01-06 20:54:52 +01:00
|
|
|
elseif fname =~ '\.lzma$' && executable("lzcat")
|
|
|
|
let decmp= "|lzcat"
|
2008-06-24 22:58:06 +00:00
|
|
|
let doro = 1
|
2010-07-28 18:17:41 +02:00
|
|
|
elseif fname =~ '\.xz$' && executable("xzcat")
|
|
|
|
let decmp= "|xzcat"
|
|
|
|
let doro = 1
|
2020-11-29 14:36:24 +01:00
|
|
|
elseif fname =~ '\.zst$' && executable("zstdcat")
|
|
|
|
let decmp= "|zstdcat"
|
|
|
|
let doro = 1
|
2025-02-06 21:10:49 +01:00
|
|
|
elseif fname =~ '\.lz4$' && executable("lz4cat")
|
|
|
|
let decmp= "|lz4cat"
|
|
|
|
let doro = 1
|
2008-06-24 22:58:06 +00:00
|
|
|
else
|
|
|
|
let decmp=""
|
|
|
|
let doro = 0
|
2010-07-28 18:17:41 +02:00
|
|
|
if fname =~ '\.bz2$\|\.gz$\|\.lzma$\|\.xz$\|\.zip$\|\.Z$'
|
2008-06-24 22:58:06 +00:00
|
|
|
setlocal bin
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2008-08-09 17:55:22 +00:00
|
|
|
if exists("g:tar_secure")
|
|
|
|
let tar_secure= " -- "
|
|
|
|
else
|
|
|
|
let tar_secure= " "
|
|
|
|
endif
|
2018-09-02 21:07:30 +02:00
|
|
|
|
2010-01-06 20:54:52 +01:00
|
|
|
if tarfile =~# '\.bz2$'
|
2011-06-19 05:09:16 +02:00
|
|
|
exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2020-01-09 21:46:04 +01:00
|
|
|
elseif tarfile =~# '\.\(gz\)$'
|
|
|
|
exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2020-01-09 21:46:04 +01:00
|
|
|
elseif tarfile =~# '\(\.tgz\|\.tbz\|\.txz\)'
|
|
|
|
if has("unix") && executable("file")
|
|
|
|
let filekind= system("file ".shellescape(tarfile,1))
|
|
|
|
else
|
|
|
|
let filekind= ""
|
|
|
|
endif
|
|
|
|
if filekind =~ "bzip2"
|
|
|
|
exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2020-01-09 21:46:04 +01:00
|
|
|
elseif filekind =~ "XZ"
|
|
|
|
exe "sil! r! xz -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2020-11-29 14:36:24 +01:00
|
|
|
elseif filekind =~ "Zstandard"
|
|
|
|
exe "sil! r! zstd --decompress --stdout -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2020-01-09 21:46:04 +01:00
|
|
|
else
|
|
|
|
exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2020-01-09 21:46:04 +01:00
|
|
|
endif
|
|
|
|
|
2008-06-24 22:58:06 +00:00
|
|
|
elseif tarfile =~# '\.lrp$'
|
2018-09-08 15:10:34 +02:00
|
|
|
exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2010-01-06 20:54:52 +01:00
|
|
|
elseif tarfile =~# '\.lzma$'
|
2011-06-19 05:09:16 +02:00
|
|
|
exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2010-07-28 18:17:41 +02:00
|
|
|
elseif tarfile =~# '\.\(xz\|txz\)$'
|
2011-06-19 05:09:16 +02:00
|
|
|
exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
2025-02-06 21:10:49 +01:00
|
|
|
elseif tarfile =~# '\.\(lz4\|tlz4\)$'
|
|
|
|
exe "sil! r! lz4 --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp
|
|
|
|
exe "read ".fname
|
2005-11-23 21:25:05 +00:00
|
|
|
else
|
2008-08-09 17:55:22 +00:00
|
|
|
if tarfile =~ '^\s*-'
|
2010-01-06 20:54:52 +01:00
|
|
|
" A file name starting with a dash is taken as an option. Prepend ./ to avoid that.
|
2008-08-09 17:55:22 +00:00
|
|
|
let tarfile = substitute(tarfile, '-', './-', '')
|
|
|
|
endif
|
2010-01-06 20:54:52 +01:00
|
|
|
exe "silent r! ".g:tar_cmd." -".g:tar_readoptions.shellescape(tarfile,1)." ".tar_secure.shellescape(fname,1).decmp
|
2024-11-11 22:39:30 +01:00
|
|
|
exe "read ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
redraw!
|
|
|
|
|
|
|
|
if v:shell_error != 0
|
|
|
|
cd ..
|
|
|
|
call s:Rmdir("_ZIPVIM_")
|
|
|
|
exe "cd ".fnameescape(curdir)
|
|
|
|
echohl Error | echo "***error*** (tar#Read) sorry, unable to open or extract ".tarfile." with ".fname | echohl None
|
2005-11-23 21:25:05 +00:00
|
|
|
endif
|
2008-06-24 22:58:06 +00:00
|
|
|
|
|
|
|
if doro
|
|
|
|
" because the reverse process of compressing changed files back into the tarball is not currently supported
|
|
|
|
setlocal ro
|
|
|
|
endif
|
|
|
|
|
2010-08-10 21:43:35 +02:00
|
|
|
let b:tarfile= a:fname
|
2008-07-13 17:41:49 +00:00
|
|
|
exe "file tarfile::".fnameescape(fname)
|
2005-11-23 21:25:05 +00:00
|
|
|
|
|
|
|
" cleanup
|
2011-06-19 05:09:16 +02:00
|
|
|
keepj sil! 0d
|
2005-11-23 21:25:05 +00:00
|
|
|
set nomod
|
|
|
|
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-11-23 21:25:05 +00:00
|
|
|
endfun
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" tar#Write: {{{2
|
|
|
|
fun! tar#Write(fname)
|
2005-11-28 23:05:55 +00:00
|
|
|
let repkeep= &report
|
|
|
|
set report=10
|
2024-11-11 22:39:30 +01:00
|
|
|
" temporary buffer variable workaround because too fucking tired. but it works now
|
|
|
|
let curdir= b:curdir
|
|
|
|
let tmpdir= b:tmpdir
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2008-08-09 17:55:22 +00:00
|
|
|
if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-'
|
|
|
|
redraw!
|
2010-01-06 20:54:52 +01:00
|
|
|
echohl WarningMsg | echo '***warning*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"'
|
2008-08-09 17:55:22 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2005-09-14 21:40:12 +00:00
|
|
|
" sanity checks
|
2006-04-05 20:41:53 +00:00
|
|
|
if !executable(g:tar_cmd)
|
2007-05-05 18:24:42 +00:00
|
|
|
redraw!
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-09-14 21:40:12 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2010-08-10 21:43:35 +02:00
|
|
|
let tarfile = substitute(b:tarfile,'tarfile:\(.\{-}\)::.*$','\1','')
|
|
|
|
let fname = substitute(b:tarfile,'tarfile:.\{-}::\(.*\)$','\1','')
|
2005-11-23 21:25:05 +00:00
|
|
|
|
|
|
|
" handle compressed archives
|
2010-01-06 20:54:52 +01:00
|
|
|
if tarfile =~# '\.bz2'
|
|
|
|
call system("bzip2 -d -- ".shellescape(tarfile,0))
|
|
|
|
let tarfile = substitute(tarfile,'\.bz2','','e')
|
|
|
|
let compress= "bzip2 -- ".shellescape(tarfile,0)
|
|
|
|
elseif tarfile =~# '\.gz'
|
2020-01-09 21:46:04 +01:00
|
|
|
call system("gzip -d -- ".shellescape(tarfile,0))
|
2005-11-23 21:25:05 +00:00
|
|
|
let tarfile = substitute(tarfile,'\.gz','','e')
|
2010-01-06 20:54:52 +01:00
|
|
|
let compress= "gzip -- ".shellescape(tarfile,0)
|
2005-11-23 21:25:05 +00:00
|
|
|
elseif tarfile =~# '\.tgz'
|
2020-01-09 21:46:04 +01:00
|
|
|
call system("gzip -d -- ".shellescape(tarfile,0))
|
2005-11-23 21:25:05 +00:00
|
|
|
let tarfile = substitute(tarfile,'\.tgz','.tar','e')
|
2010-01-06 20:54:52 +01:00
|
|
|
let compress= "gzip -- ".shellescape(tarfile,0)
|
2005-11-23 21:25:05 +00:00
|
|
|
let tgz = 1
|
2010-07-28 18:17:41 +02:00
|
|
|
elseif tarfile =~# '\.xz'
|
|
|
|
call system("xz -d -- ".shellescape(tarfile,0))
|
|
|
|
let tarfile = substitute(tarfile,'\.xz','','e')
|
|
|
|
let compress= "xz -- ".shellescape(tarfile,0)
|
2020-11-29 14:36:24 +01:00
|
|
|
elseif tarfile =~# '\.zst'
|
2024-01-08 20:02:14 +01:00
|
|
|
call system("zstd --decompress --rm -- ".shellescape(tarfile,0))
|
2020-11-29 14:36:24 +01:00
|
|
|
let tarfile = substitute(tarfile,'\.zst','','e')
|
2024-01-08 20:02:14 +01:00
|
|
|
let compress= "zstd --rm -- ".shellescape(tarfile,0)
|
2025-02-06 21:10:49 +01:00
|
|
|
elseif tarfile =~# '\.lz4'
|
|
|
|
call system("lz4 --decompress --rm -- ".shellescape(tarfile,0))
|
|
|
|
let tarfile = substitute(tarfile,'\.lz4','','e')
|
|
|
|
let compress= "lz4 --rm -- ".shellescape(tarfile,0)
|
2010-07-28 18:17:41 +02:00
|
|
|
elseif tarfile =~# '\.lzma'
|
|
|
|
call system("lzma -d -- ".shellescape(tarfile,0))
|
|
|
|
let tarfile = substitute(tarfile,'\.lzma','','e')
|
|
|
|
let compress= "lzma -- ".shellescape(tarfile,0)
|
2005-09-14 21:40:12 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
if v:shell_error != 0
|
2007-05-05 18:24:42 +00:00
|
|
|
redraw!
|
2005-11-23 21:25:05 +00:00
|
|
|
echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None
|
2005-09-14 21:40:12 +00:00
|
|
|
else
|
2005-11-23 21:25:05 +00:00
|
|
|
|
2005-12-29 22:51:09 +00:00
|
|
|
if fname =~ '/'
|
|
|
|
let dirpath = substitute(fname,'/[^/]\+$','','e')
|
2013-04-24 18:51:19 +02:00
|
|
|
if has("win32unix") && executable("cygpath")
|
2010-01-06 20:54:52 +01:00
|
|
|
let dirpath = substitute(system("cygpath ".shellescape(dirpath, 0)),'\n','','e')
|
2005-12-29 22:51:09 +00:00
|
|
|
endif
|
|
|
|
call mkdir(dirpath,"p")
|
|
|
|
endif
|
2005-11-23 21:25:05 +00:00
|
|
|
if tarfile !~ '/'
|
|
|
|
let tarfile= curdir.'/'.tarfile
|
|
|
|
endif
|
2008-08-09 17:55:22 +00:00
|
|
|
if tarfile =~ '^\s*-'
|
|
|
|
" A file name starting with a dash may be taken as an option. Prepend ./ to avoid that.
|
|
|
|
let tarfile = substitute(tarfile, '-', './-', '')
|
|
|
|
endif
|
2024-01-08 20:02:14 +01:00
|
|
|
|
2008-08-09 17:55:22 +00:00
|
|
|
if exists("g:tar_secure")
|
|
|
|
let tar_secure= " -- "
|
|
|
|
else
|
|
|
|
let tar_secure= " "
|
|
|
|
endif
|
2008-06-24 22:58:06 +00:00
|
|
|
exe "w! ".fnameescape(fname)
|
2013-04-24 18:51:19 +02:00
|
|
|
if has("win32unix") && executable("cygpath")
|
2010-01-06 20:54:52 +01:00
|
|
|
let tarfile = substitute(system("cygpath ".shellescape(tarfile,0)),'\n','','e')
|
2005-11-23 21:25:05 +00:00
|
|
|
endif
|
2024-01-08 20:02:14 +01:00
|
|
|
|
2005-11-23 21:25:05 +00:00
|
|
|
" delete old file from tarfile
|
2020-01-09 21:46:04 +01:00
|
|
|
call system(g:tar_cmd." ".g:tar_delfile." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0))
|
2005-11-23 21:25:05 +00:00
|
|
|
if v:shell_error != 0
|
2007-05-05 18:24:42 +00:00
|
|
|
redraw!
|
2008-06-24 22:58:06 +00:00
|
|
|
echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None
|
2005-11-23 21:25:05 +00:00
|
|
|
else
|
2024-01-08 20:02:14 +01:00
|
|
|
|
|
|
|
" update tarfile with new file
|
2010-01-06 20:54:52 +01:00
|
|
|
call system(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0))
|
2005-11-23 21:25:05 +00:00
|
|
|
if v:shell_error != 0
|
2007-05-05 18:24:42 +00:00
|
|
|
redraw!
|
2008-06-24 22:58:06 +00:00
|
|
|
echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None
|
2005-11-23 21:25:05 +00:00
|
|
|
elseif exists("compress")
|
|
|
|
call system(compress)
|
|
|
|
if exists("tgz")
|
|
|
|
call rename(tarfile.".gz",substitute(tarfile,'\.tar$','.tgz','e'))
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
" support writing tarfiles across a network
|
|
|
|
if s:tblfile_{winnr()} =~ '^\a\+://'
|
|
|
|
let tblfile= s:tblfile_{winnr()}
|
2020-01-09 21:46:04 +01:00
|
|
|
1split|noswapfile enew
|
2010-01-06 20:54:52 +01:00
|
|
|
let binkeep= &l:binary
|
2005-11-23 21:25:05 +00:00
|
|
|
let eikeep = &ei
|
|
|
|
set binary ei=all
|
2020-01-09 21:46:04 +01:00
|
|
|
exe "noswapfile e! ".fnameescape(tarfile)
|
2005-11-23 21:25:05 +00:00
|
|
|
call netrw#NetWrite(tblfile)
|
2010-01-06 20:54:52 +01:00
|
|
|
let &ei = eikeep
|
|
|
|
let &l:binary = binkeep
|
2005-11-23 21:25:05 +00:00
|
|
|
q!
|
|
|
|
unlet s:tblfile_{winnr()}
|
|
|
|
endif
|
2005-09-14 21:40:12 +00:00
|
|
|
endif
|
2024-01-08 20:02:14 +01:00
|
|
|
|
2005-09-14 21:40:12 +00:00
|
|
|
" cleanup and restore current directory
|
|
|
|
cd ..
|
2005-11-23 21:25:05 +00:00
|
|
|
call s:Rmdir("_ZIPVIM_")
|
2008-07-13 17:41:49 +00:00
|
|
|
exe "cd ".fnameescape(curdir)
|
2005-09-14 21:40:12 +00:00
|
|
|
setlocal nomod
|
|
|
|
|
2005-11-28 23:05:55 +00:00
|
|
|
let &report= repkeep
|
2005-09-14 21:40:12 +00:00
|
|
|
endfun
|
|
|
|
|
2013-04-24 18:51:19 +02:00
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" tar#Diff: {{{2
|
|
|
|
fun! tar#Diff(userfname,fname)
|
|
|
|
let fname= a:fname
|
|
|
|
if a:userfname != ""
|
|
|
|
let fname= a:userfname
|
|
|
|
endif
|
|
|
|
if filereadable(fname)
|
|
|
|
" sets current file (from tarball) for diff'ing
|
|
|
|
" splits window vertically
|
|
|
|
" opens original file, sets it for diff'ing
|
|
|
|
" sets up b:tardiff_otherbuf variables so each buffer knows about the other (for closing purposes)
|
|
|
|
diffthis
|
|
|
|
wincmd v
|
2020-01-09 21:46:04 +01:00
|
|
|
exe "noswapfile e ".fnameescape(fname)
|
2013-04-24 18:51:19 +02:00
|
|
|
diffthis
|
|
|
|
else
|
|
|
|
redraw!
|
|
|
|
echo "***warning*** unable to read file<".fname.">"
|
|
|
|
endif
|
|
|
|
endfun
|
|
|
|
|
2020-01-09 21:46:04 +01:00
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" tar#Extract: extract a file from a (possibly compressed) tar archive {{{2
|
|
|
|
fun! tar#Extract()
|
|
|
|
|
|
|
|
let repkeep= &report
|
|
|
|
set report=10
|
|
|
|
let fname= getline(".")
|
|
|
|
|
|
|
|
if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-'
|
|
|
|
redraw!
|
|
|
|
echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" sanity check
|
|
|
|
if fname =~ '^"'
|
|
|
|
let &report= repkeep
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let tarball = expand("%")
|
|
|
|
let tarbase = substitute(tarball,'\..*$','','')
|
|
|
|
|
|
|
|
let extractcmd= netrw#WinPath(g:tar_extractcmd)
|
|
|
|
if filereadable(tarbase.".tar")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tgz")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-z","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tgz ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tgz ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tar.gz")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-z","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tar.gz ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.gz ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tbz")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-j","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tbz ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd."j ".tarbase.".tbz ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tar.bz2")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-j","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tar.bz2 ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd."j ".tarbase.".tar.bz2 ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".txz")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-J","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".txz ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".txz ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tar.xz")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-J","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tar.xz ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.xz ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
2020-11-29 14:36:24 +01:00
|
|
|
|
2024-01-08 20:02:14 +01:00
|
|
|
elseif filereadable(tarbase.".tzst")
|
2020-11-29 14:36:24 +01:00
|
|
|
let extractcmd= substitute(extractcmd,"-","--zstd","")
|
2024-01-08 20:02:14 +01:00
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tzst ".shellescape(fname))
|
2020-11-29 14:36:24 +01:00
|
|
|
if v:shell_error != 0
|
2024-01-08 20:02:14 +01:00
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tzst ".fname.": failed!" | echohl NONE
|
2020-11-29 14:36:24 +01:00
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tar.zst")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","--zstd","")
|
2024-01-08 20:02:14 +01:00
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tar.zst ".shellescape(fname))
|
2020-11-29 14:36:24 +01:00
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.zst ".fname.": failed!" | echohl NONE
|
2025-02-06 21:10:49 +01:00
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tlz4")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-I lz4","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tlz4 ".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tlz4 ".fname.": failed!" | echohl NONE
|
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
|
|
|
|
|
|
|
elseif filereadable(tarbase.".tar.lz4")
|
|
|
|
let extractcmd= substitute(extractcmd,"-","-I lz4","")
|
|
|
|
call system(extractcmd." ".shellescape(tarbase).".tar.lz4".shellescape(fname))
|
|
|
|
if v:shell_error != 0
|
|
|
|
echohl Error | echo "***error*** ".extractcmd." ".tarbase.".tar.lz4 ".fname.": failed!" | echohl NONE
|
2020-11-29 14:36:24 +01:00
|
|
|
else
|
|
|
|
echo "***note*** successfully extracted ".fname
|
|
|
|
endif
|
2020-01-09 21:46:04 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
" restore option
|
|
|
|
let &report= repkeep
|
|
|
|
endfun
|
|
|
|
|
2005-09-14 21:40:12 +00:00
|
|
|
" ---------------------------------------------------------------------
|
2010-01-06 20:54:52 +01:00
|
|
|
" s:Rmdir: {{{2
|
2005-09-14 21:40:12 +00:00
|
|
|
fun! s:Rmdir(fname)
|
|
|
|
if has("unix")
|
2010-01-06 20:54:52 +01:00
|
|
|
call system("/bin/rm -rf -- ".shellescape(a:fname,0))
|
2005-09-14 21:40:12 +00:00
|
|
|
elseif has("win32") || has("win95") || has("win64") || has("win16")
|
|
|
|
if &shell =~? "sh$"
|
2010-01-06 20:54:52 +01:00
|
|
|
call system("/bin/rm -rf -- ".shellescape(a:fname,0))
|
2005-09-14 21:40:12 +00:00
|
|
|
else
|
2010-01-06 20:54:52 +01:00
|
|
|
call system("del /S ".shellescape(a:fname,0))
|
2005-09-14 21:40:12 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfun
|
|
|
|
|
2008-06-24 22:58:06 +00:00
|
|
|
" ---------------------------------------------------------------------
|
2010-01-06 20:54:52 +01:00
|
|
|
" tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2
|
|
|
|
fun! tar#Vimuntar(...)
|
|
|
|
let tarball = expand("%")
|
|
|
|
let tarbase = substitute(tarball,'\..*$','','')
|
|
|
|
let tarhome = expand("%:p")
|
|
|
|
if has("win32") || has("win95") || has("win64") || has("win16")
|
|
|
|
let tarhome= substitute(tarhome,'\\','/','g')
|
|
|
|
endif
|
|
|
|
let tarhome= substitute(tarhome,'/[^/]*$','','')
|
|
|
|
let tartail = expand("%:t")
|
|
|
|
let curdir = getcwd()
|
|
|
|
" set up vimhome
|
|
|
|
if a:0 > 0 && a:1 != ""
|
|
|
|
let vimhome= a:1
|
|
|
|
else
|
|
|
|
let vimhome= vimball#VimballHome()
|
|
|
|
endif
|
|
|
|
|
|
|
|
if simplify(curdir) != simplify(vimhome)
|
|
|
|
" copy (possibly compressed) tarball to .vim/vimfiles
|
|
|
|
call system(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome))
|
|
|
|
exe "cd ".fnameescape(vimhome)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" if necessary, decompress the tarball; then, extract it
|
|
|
|
if tartail =~ '\.tgz'
|
2020-01-09 21:46:04 +01:00
|
|
|
if executable("gunzip")
|
2010-01-06 20:54:52 +01:00
|
|
|
silent exe "!gunzip ".shellescape(tartail)
|
|
|
|
elseif executable("gzip")
|
|
|
|
silent exe "!gzip -d ".shellescape(tartail)
|
2008-07-13 17:41:49 +00:00
|
|
|
else
|
2021-09-09 21:55:11 +02:00
|
|
|
echoerr "unable to decompress<".tartail."> on this system"
|
2010-01-06 20:54:52 +01:00
|
|
|
if simplify(curdir) != simplify(tarhome)
|
|
|
|
" remove decompressed tarball, restore directory
|
|
|
|
call delete(tartail.".tar")
|
|
|
|
exe "cd ".fnameescape(curdir)
|
|
|
|
endif
|
|
|
|
return
|
2008-07-13 17:41:49 +00:00
|
|
|
endif
|
2008-06-24 22:58:06 +00:00
|
|
|
else
|
2010-01-06 20:54:52 +01:00
|
|
|
call vimball#Decompress(tartail,0)
|
2008-06-24 22:58:06 +00:00
|
|
|
endif
|
2010-01-06 20:54:52 +01:00
|
|
|
let extractcmd= netrw#WinPath(g:tar_extractcmd)
|
|
|
|
call system(extractcmd." ".shellescape(tarbase.".tar"))
|
|
|
|
|
|
|
|
" set up help
|
|
|
|
if filereadable("doc/".tarbase.".txt")
|
|
|
|
exe "helptags ".getcwd()."/doc"
|
|
|
|
endif
|
|
|
|
|
|
|
|
if simplify(tarhome) != simplify(vimhome)
|
|
|
|
" remove decompressed tarball, restore directory
|
|
|
|
call delete(vimhome."/".tarbase.".tar")
|
|
|
|
exe "cd ".fnameescape(curdir)
|
|
|
|
endif
|
2008-06-24 22:58:06 +00:00
|
|
|
endfun
|
|
|
|
|
2010-01-06 20:54:52 +01:00
|
|
|
" =====================================================================
|
2005-11-23 21:25:05 +00:00
|
|
|
" Modelines And Restoration: {{{1
|
|
|
|
let &cpo= s:keepcpo
|
|
|
|
unlet s:keepcpo
|
2008-06-24 22:58:06 +00:00
|
|
|
" vim:ts=8 fdm=marker
|