| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  | " tar.vim: Handles browsing tarfiles | 
					
						
							|  |  |  | "            AUTOLOAD PORTION | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  | " Date:			Apr 17, 2013 | 
					
						
							|  |  |  | " Version:		29 | 
					
						
							|  |  |  | " Maintainer:	Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00: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
										 |  |  | " | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  | " Copyright:    Copyright (C) 2005-2011 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. | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "     call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  | let g:loaded_tar= "v29" | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  | "DechoTabOn | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "call Decho("loading autoload/tar.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") | 
					
						
							|  |  |  |  let g:tar_readoptions= "OPxf" | 
					
						
							|  |  |  | 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 | 
					
						
							| 
									
										
										
										
											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") | 
					
						
							|  |  |  |  let g:tar_extractcmd= "tar -xf" | 
					
						
							|  |  |  | 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 | 
					
						
							| 
									
										
										
										
											2008-06-24 22:58:06 +00:00
										 |  |  | " call Decho("g:tar_shq<".g:tar_shq.">") | 
					
						
							| 
									
										
										
										
											2007-05-05 18:24:42 +00:00
										 |  |  | 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) | 
					
						
							|  |  |  | "  call Dfunc("tar#Browse(tarfile<".a: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
										 |  |  | "   call Dret("tar#Browse") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if !filereadable(a:tarfile) | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  | "   call Decho('a:tarfile<'.a:tarfile.'> not filereadable') | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |    if a:tarfile !~# '^\a\+://' | 
					
						
							|  |  |  |     " if its 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
										 |  |  | "   call Dret("tar#Browse : file<".a:tarfile."> not readable") | 
					
						
							|  |  |  |    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 | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  | "  call Decho("printing 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("$") | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  |   if tarfile =~# '\.\(gz\|tgz\)$' | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "   call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " | 
					
						
							| 
									
										
										
										
											2008-06-24 22:58:06 +00:00
										 |  |  |   elseif tarfile =~# '\.lrp' | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "   call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +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\)$' | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "   call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | 
					
						
							| 
									
										
										
										
											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\)$' | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "   call Decho("3: exe silent r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | 
					
						
							| 
									
										
										
										
											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\)$' | 
					
						
							|  |  |  | "   call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    exe "sil! r! xz --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 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "   call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,0)) | 
					
						
							| 
									
										
										
										
											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.">" | 
					
						
							|  |  |  | "   call Dret("tar#Browse : a:tarfile<".a:tarfile.">") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2007-05-05 18:24:42 +00:00
										 |  |  |   if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)') | 
					
						
							|  |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |    echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    keepj sil! %d | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |    let eikeep= &ei | 
					
						
							|  |  |  |    set ei=BufReadCmd,FileReadCmd | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |    exe "r ".fnameescape(a:tarfile) | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |    let &ei= eikeep | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    keepj sil! 1d | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  | "   call Dret("tar#Browse : a:tarfile<".a:tarfile.">") | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  |    return | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setlocal noma nomod ro | 
					
						
							|  |  |  |   noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-28 23:05:55 +00:00
										 |  |  |   let &report= repkeep | 
					
						
							| 
									
										
										
										
											2010-08-10 21:43:35 +02:00
										 |  |  | "  call Dret("tar#Browse : b:tarfile<".b:tarfile.">") | 
					
						
							| 
									
										
										
										
											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() | 
					
						
							| 
									
										
										
										
											2010-08-10 21:43:35 +02:00
										 |  |  | "  call Dfunc("TarBrowseSelect() b:tarfile<".b:tarfile."> curfile<".expand("%").">") | 
					
						
							| 
									
										
										
										
											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(".") | 
					
						
							|  |  |  | "  call Decho("fname<".fname.">") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | "   call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') | 
					
						
							|  |  |  |    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
										 |  |  | "   call Dret("TarBrowseSelect") | 
					
						
							|  |  |  |    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
										 |  |  | 
 | 
					
						
							|  |  |  |   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
										 |  |  | "  call Dret("TarBrowseSelect : s:tblfile_".winnr()."<".s:tblfile_{winnr()}.">") | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " tar#Read: {{{2 | 
					
						
							|  |  |  | fun! tar#Read(fname,mode) | 
					
						
							|  |  |  | "  call Dfunc("tar#Read(fname<".a:fname.">,mode=".a: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','') | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | "  call Decho("tarfile<".tarfile.">") | 
					
						
							|  |  |  | "  call Decho("fname<".fname.">") | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |   elseif      fname =~ '\.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 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |   if tarfile =~# '\.bz2$' | 
					
						
							|  |  |  | "   call Decho("7: exe silent r! bzip2 -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |   elseif tarfile =~# '\.\(gz\|tgz\)$' | 
					
						
							|  |  |  | "   call Decho("5: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.shellescape(fname,1)) | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp | 
					
						
							| 
									
										
										
										
											2008-06-24 22:58:06 +00:00
										 |  |  |   elseif tarfile =~# '\.lrp$' | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "   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) | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |   elseif tarfile =~# '\.lzma$' | 
					
						
							|  |  |  | "   call Decho("7: exe silent r! lzma -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2010-07-28 18:17:41 +02:00
										 |  |  |   elseif tarfile =~# '\.\(xz\|txz\)$' | 
					
						
							|  |  |  | "   call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | "   call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions.tar_secure.shellescape(tarfile,1)." ".shellescape(fname,1).decmp) | 
					
						
							|  |  |  |    exe "silent r! ".g:tar_cmd." -".g:tar_readoptions.shellescape(tarfile,1)." ".tar_secure.shellescape(fname,1).decmp | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2010-08-10 21:43:35 +02:00
										 |  |  | "  call Dret("tar#Read : b:tarfile<".b:tarfile.">") | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " tar#Write: {{{2 | 
					
						
							|  |  |  | fun! tar#Write(fname) | 
					
						
							| 
									
										
										
										
											2010-08-10 21:43:35 +02:00
										 |  |  | "  call Dfunc("tar#Write(fname<".a:fname.">) b:tarfile<".b:tarfile."> tblfile_".winnr()."<".s:tblfile_{winnr()}.">") | 
					
						
							| 
									
										
										
										
											2005-11-28 23:05:55 +00:00
										 |  |  |   let repkeep= &report | 
					
						
							|  |  |  |   set report=10 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | "   call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"') | 
					
						
							|  |  |  |    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! | 
					
						
							| 
									
										
										
										
											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-09-14 21:40:12 +00:00
										 |  |  | "   call Dret("tar#Write") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if !exists("*mkdir") | 
					
						
							| 
									
										
										
										
											2007-05-05 18:24:42 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |    echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None | 
					
						
							| 
									
										
										
										
											2005-11-28 23:05:55 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-14 21:40:12 +00:00
										 |  |  | "   call Dret("tar#Write") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let curdir= getcwd() | 
					
						
							|  |  |  |   let tmpdir= tempname() | 
					
						
							|  |  |  | "  call Decho("orig tempname<".tmpdir.">") | 
					
						
							|  |  |  |   if tmpdir =~ '\.' | 
					
						
							|  |  |  |    let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Decho("tmpdir<".tmpdir.">") | 
					
						
							|  |  |  |   call mkdir(tmpdir,"p") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " attempt to change to the indicated directory | 
					
						
							|  |  |  |   try | 
					
						
							| 
									
										
										
										
											2008-06-24 22:58:06 +00:00
										 |  |  |    exe "cd ".fnameescape(tmpdir) | 
					
						
							| 
									
										
										
										
											2005-09-14 21:40:12 +00:00
										 |  |  |   catch /^Vim\%((\a\+)\)\=:E344/ | 
					
						
							| 
									
										
										
										
											2007-05-05 18:24:42 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |    echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None | 
					
						
							| 
									
										
										
										
											2005-11-28 23:05:55 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-14 21:40:12 +00:00
										 |  |  | "   call Dret("tar#Write") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endtry | 
					
						
							|  |  |  | "  call Decho("current directory now: ".getcwd()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |   " place temporary files under .../_ZIPVIM_/ | 
					
						
							|  |  |  |   if isdirectory("_ZIPVIM_") | 
					
						
							|  |  |  |    call s:Rmdir("_ZIPVIM_") | 
					
						
							| 
									
										
										
										
											2005-09-14 21:40:12 +00:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |   call mkdir("_ZIPVIM_") | 
					
						
							|  |  |  |   cd _ZIPVIM_ | 
					
						
							| 
									
										
										
										
											2005-09-14 21:40:12 +00:00
										 |  |  | "  call Decho("current directory now: ".getcwd()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  | "   call Decho("compress<".compress.">") | 
					
						
							|  |  |  |   elseif tarfile =~# '\.gz' | 
					
						
							|  |  |  |    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) | 
					
						
							| 
									
										
										
										
											2008-08-09 17:55:22 +00:00
										 |  |  | "   call Decho("compress<".compress.">") | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |   elseif tarfile =~# '\.tgz' | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +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
										 |  |  | "   call Decho("compress<".compress.">") | 
					
						
							|  |  |  |   elseif tarfile =~# '\.xz' | 
					
						
							|  |  |  |    call system("xz -d -- ".shellescape(tarfile,0)) | 
					
						
							|  |  |  |    let tarfile = substitute(tarfile,'\.xz','','e') | 
					
						
							|  |  |  |    let compress= "xz -- ".shellescape(tarfile,0) | 
					
						
							|  |  |  | "   call Decho("compress<".compress.">") | 
					
						
							|  |  |  |   elseif tarfile =~# '\.lzma' | 
					
						
							|  |  |  |    call system("lzma -d -- ".shellescape(tarfile,0)) | 
					
						
							|  |  |  |    let tarfile = substitute(tarfile,'\.lzma','','e') | 
					
						
							|  |  |  |    let compress= "lzma -- ".shellescape(tarfile,0) | 
					
						
							| 
									
										
										
										
											2008-08-09 17:55:22 +00:00
										 |  |  | "   call Decho("compress<".compress.">") | 
					
						
							| 
									
										
										
										
											2005-09-14 21:40:12 +00:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2008-06-24 22:58:06 +00:00
										 |  |  | "  call Decho("tarfile<".tarfile.">") | 
					
						
							| 
									
										
										
										
											2005-09-14 21:40:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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
										 |  |  | 
 | 
					
						
							|  |  |  | "   call Decho("tarfile<".tarfile."> fname<".fname.">") | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  | "   call Decho("tarfile<".tarfile."> fname<".fname.">") | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |    " delete old file from tarfile | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "   call Decho("system(".g:tar_cmd." --delete -f ".shellescape(tarfile,0)." -- ".shellescape(fname,0).")") | 
					
						
							|  |  |  |    call system(g:tar_cmd." --delete -f ".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 | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |     " update tarfile with new file  | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  | "    call Decho(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) | 
					
						
							|  |  |  |     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 Decho("call system(".compress.")") | 
					
						
							|  |  |  |      call system(compress) | 
					
						
							|  |  |  |      if exists("tgz") | 
					
						
							|  |  |  | "      call Decho("rename(".tarfile.".gz,".substitute(tarfile,'\.tar$','.tgz','e').")") | 
					
						
							|  |  |  |       call rename(tarfile.".gz",substitute(tarfile,'\.tar$','.tgz','e')) | 
					
						
							|  |  |  |      endif | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  |    endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    " support writing tarfiles across a network | 
					
						
							|  |  |  |    if s:tblfile_{winnr()} =~ '^\a\+://' | 
					
						
							|  |  |  | "    call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">") | 
					
						
							|  |  |  |     let tblfile= s:tblfile_{winnr()} | 
					
						
							|  |  |  |     1split|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 | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |     exe "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 | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   " 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
										 |  |  | "  call Dret("tar#Write") | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " tar#Diff: {{{2 | 
					
						
							|  |  |  | fun! tar#Diff(userfname,fname) | 
					
						
							|  |  |  | "  call Dfunc("tar#Diff(userfname<".a:userfname."> fname<".a: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 | 
					
						
							|  |  |  |    exe "e ".fnameescape(fname) | 
					
						
							|  |  |  |    diffthis | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |    redraw! | 
					
						
							|  |  |  |    echo "***warning*** unable to read file<".fname.">" | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Dret("tar#Diff") | 
					
						
							|  |  |  | 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) | 
					
						
							|  |  |  | "  call Dfunc("Rmdir(fname<".a: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 | 
					
						
							|  |  |  | "  call Dret("Rmdir") | 
					
						
							|  |  |  | 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(...) | 
					
						
							|  |  |  | "  call Dfunc("tar#Vimuntar() a:0=".a:0." a:1<".(exists("a:1")? a:1 : "-n/a-").">") | 
					
						
							|  |  |  |   let tarball = expand("%") | 
					
						
							|  |  |  | "  call Decho("tarball<".tarball.">") | 
					
						
							|  |  |  |   let tarbase = substitute(tarball,'\..*$','','') | 
					
						
							|  |  |  | "  call Decho("tarbase<".tarbase.">") | 
					
						
							|  |  |  |   let tarhome = expand("%:p") | 
					
						
							|  |  |  |   if has("win32") || has("win95") || has("win64") || has("win16") | 
					
						
							|  |  |  |    let tarhome= substitute(tarhome,'\\','/','g') | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   let tarhome= substitute(tarhome,'/[^/]*$','','') | 
					
						
							|  |  |  | "  call Decho("tarhome<".tarhome.">") | 
					
						
							|  |  |  |   let tartail = expand("%:t") | 
					
						
							|  |  |  | "  call Decho("tartail<".tartail.">") | 
					
						
							|  |  |  |   let curdir  = getcwd() | 
					
						
							|  |  |  | "  call Decho("curdir <".curdir.">") | 
					
						
							|  |  |  |   " set up vimhome | 
					
						
							|  |  |  |   if a:0 > 0 && a:1 != "" | 
					
						
							|  |  |  |    let vimhome= a:1 | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |    let vimhome= vimball#VimballHome() | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Decho("vimhome<".vimhome.">") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "  call Decho("curdir<".curdir."> vimhome<".vimhome.">") | 
					
						
							|  |  |  |   if simplify(curdir) != simplify(vimhome) | 
					
						
							|  |  |  |    " copy (possibly compressed) tarball to .vim/vimfiles | 
					
						
							|  |  |  | "   call Decho(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | 
					
						
							|  |  |  |    call system(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | 
					
						
							|  |  |  | "   call Decho("exe cd ".fnameescape(vimhome)) | 
					
						
							|  |  |  |    exe "cd ".fnameescape(vimhome) | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Decho("getcwd<".getcwd().">") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " if necessary, decompress the tarball; then, extract it | 
					
						
							|  |  |  |   if tartail =~ '\.tgz' | 
					
						
							|  |  |  |    if executable("gunzip") | 
					
						
							|  |  |  |     silent exe "!gunzip ".shellescape(tartail) | 
					
						
							|  |  |  |    elseif executable("gzip") | 
					
						
							|  |  |  |     silent exe "!gzip -d ".shellescape(tartail) | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |    else | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |     echoerr "unable to decompress<".tartail."> on this sytem" | 
					
						
							|  |  |  |     if simplify(curdir) != simplify(tarhome) | 
					
						
							|  |  |  |      " remove decompressed tarball, restore directory | 
					
						
							|  |  |  | "     call Decho("delete(".tartail.".tar)") | 
					
						
							|  |  |  |      call delete(tartail.".tar") | 
					
						
							|  |  |  | "     call Decho("exe cd ".fnameescape(curdir)) | 
					
						
							|  |  |  |      exe "cd ".fnameescape(curdir) | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  | "    call Dret("tar#Vimuntar") | 
					
						
							|  |  |  |     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 Decho("system(".extractcmd." ".shellescape(tarbase.".tar").")") | 
					
						
							|  |  |  |   call system(extractcmd." ".shellescape(tarbase.".tar")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " set up help | 
					
						
							|  |  |  |   if filereadable("doc/".tarbase.".txt") | 
					
						
							|  |  |  | "   call Decho("exe helptags ".getcwd()."/doc") | 
					
						
							|  |  |  |    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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "  call Dret("tar#Vimuntar") | 
					
						
							| 
									
										
										
										
											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 |