Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: some tar problems fixed



> tar --directory=/tmp xvzf archiv<TAB>, on the other hand,
> will work, but it is merely doing a _path_files -W /tmp,
> thus losing all the smarts it would have without the
> --directory.  This should also be calling _tar_archive
> which in turn should do a -W /tmp.

Either I'm confused now or I was mislead before,
since GNU tar here doesn't seem to be behaving this way... so
I'm leaving a useless parser for --directory (excluding -C still)
in even though I've removed its application.  

This should handle -Cf now, but not -fC, which, of course, requires
the positions of directory and tarfile to be reversed.

Index: Completion/User/_tar
===================================================================
RCS file: /cvs/zsh/zsh/Completion/User/_tar,v
retrieving revision 1.1.1.13
diff -u -r1.1.1.13 _tar
--- Completion/User/_tar	1999/11/16 13:08:21	1.1.1.13
+++ Completion/User/_tar	1999/12/17 04:32:10
@@ -47,14 +47,21 @@
 # is searched after a `--file=' long option, in the third word if the
 # second one didn't start with a hyphen but contained a `f', and after 
 # an option argument starting with only one hyphen and containing a `f'.
+# unless that option argument also contains a `C'.
 
 tmp="$words[(I)--file=*]"
+tmpb="$words[(I)-*Cf*~--*]}"
+
 if (( tmp )); then
   tf=${~words[tmp][8,-1]}
   _tar_cmd="f$_tar_cmd"
 elif [[ "$words[2]" != -* && "$words[2]" = *f* ]]; then
   tf=${~words[3]}
   _tar_cmd="f$_tar_cmd"
+elif (( tmpb )); then
+  tf=${~words[tmpb+2]}
+  wdir=${~words[tmpb+1]}
+  _tar_cmd="Cf$_tar_cmd"
 else
   tmp="${words[(I)-*f*~--*]}"
   if (( tmp )); then
@@ -63,6 +70,18 @@
   fi
 fi
 
+# See if we should use a path prefix.  We have to use eval as the dir can
+# be any unevaluated thing which appears on the command line, including a
+# parameter.
+
+# This isn't used right now.
+
+tmp=${words[(r)--dir[a-z]#=*]}
+
+if [[ -n $tmp ]]; then
+  eval "wdir=(${tmp#*=})"
+fi
+
 # Now we complete...
 
 if [[ "$PREFIX" = --* ]]; then
@@ -73,22 +92,34 @@
                  '*=(PROG|COMMAND)*:program:_command_names -e' \
 		 '*=ARCHIVE*:archive: _tar_archive' \
 		 '*=NAME*:file:_files' \
+		 '*=DIR*:directory:_files -/' \
 		 '*=CONTROL*::version control:(t numbered nil existing never simple)'
 
 elif [[ ( CURRENT -gt 2 && "$words[CURRENT-1]" = -*f* &&
-          "$words[CURRENT-1]" != --* ) ||
-        ( CURRENT -eq 3 && "$words[2]" = *f* && "$words[2]" != -* ) ]]; then
+          "$words[CURRENT-1]" != --* && "$words[CURRENT-1]" != -*Cf* ) ||
+        ( CURRENT -eq 3 && "$words[2]" = *f* && "$words[2]" != -* &&
+          "$words[2]" != *Cf* ) ||
+        ( CURRENT -gt 2 && "$words[CURRENT-2]" = -*Cf* &&
+          "$words[CURRENT-2]" != --* && "$words[CURRENT-1]" != --* ) ||
+        ( CURRENT -eq 4 && "$words[2]" = *Cf* && "$words[2]" != -* ) ]]; then
 
   # ...archive files if we think they are wanted here.
 
   _tar_archive
 
+elif [[ ( CURRENT -gt 2 && "$words[CURRENT-1]" = -*Cf*) ||
+        ( CURRENT -eq 3 && "$words[2]" = *Cf* ) ]]; then
+
+  # a directory for -C
+
+  _files -/
+
 elif [[ ( "$_tar_cmd" = *[xt]* || -n $del ) && -n "$tf" ]]; then
 
   # ...and files from the archive if we found an archive name and tar
   # commands. We run `tar t...' on the file, keeping the list of
   # filenames cached, plus the name of the tarfile so we know if it
-  # changes.
+  # changes.  We skip this test if the alleged archive is not a file.
 
   local largs=-tf expl
 
@@ -96,13 +127,15 @@
     largs=-tzf
   elif [[ $_tar_cmd = *Z* ]]; then
     largs=-tZf
+  elif [[ $_tar_cmd = *I* ]]; then
+    largs=-tIf
   else
-    # Some random compression program e.g. bzip2
+    # Some random compression program
     tmp="${words[(r)--use-comp*]}"
     [[ -n $tmp ]] && largs=($tmp -tf)
   fi
 
-  if [[ $tf != $_tar_cache_name ]]; then
+  if [[ $tf != $_tar_cache_name && -f $tf ]]; then
     _tar_cache_list=("${(@f)$($words[1] $largs $tf)}")
     _tar_cache_name=$tf
   fi
@@ -110,15 +143,5 @@
   _wanted files expl 'file from archive' &&
       _multi_parts "$expl[@]" / _tar_cache_list
 else
-  
-  # See if we should use a path prefix.  We have to use eval as the dir can
-  # be any unevaluated thing which appears on the command line, including a
-  # parameter.
-  tmp=${words[(r)--dir[a-z]#=*]}
-  if [[ -n $tmp ]]; then
-    eval "tmp=(${tmp#*=})"
-    _path_files -W tmp
-  else
     _files
-  fi
 fi



Messages sorted by: Reverse Date, Date, Thread, Author