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

Re: Quoting problems with _zip (unzip) completer



On Mon, 17 Aug 2009 21:58:19 +0100
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> So please watch out for any anomalous _arguments quoting behaviour.

Found one in _rm... but it's not a knock-on effect of this patch, it's
another thing that was already broken.

  rm stuff <TAB>

is supposed to exclude "stuff" from being completed again by using the
-F option to _files by together with the line from _arguments:

    ignored=(${line//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
    _files -F ignored && ret=0

However, the code for "_files -F <array>" was
broken:  instead of appending the contents of <array> after the -F to
the contents of the existing array, it appended the name <array>.

After fixing this, I'm gratified to find that in a directory containing
files called "normal" and "foo[bar", it's possible to have both files
ignored owing to the previous fix (with just this fix, and not the
previous one, it only works for "normal").

(I'm not *quite* sure how this works, actually.  The extra quoting shown
in the code above protects pattern characters, since we're actually
passing a pattern, not a file name, so 'foo\[bar' from line becomes
'foo\\\[bar'.  Unquoting the pattern characters gives 'foo\[bar' back as
a literal match.  I don't understand why this matches the file...  I'm
going to pretend I didn't notice.)

I'm a bit surprised nobody noticed this wasn't working.  If anyone finds
this has a negative rather an a positive effect on ignoring files in
"rm" completion, please try to reproduce it starting from "zsh -f".

Index: Completion/Unix/Type/_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_files,v
retrieving revision 1.10
diff -u -r1.10 _files
--- Completion/Unix/Type/_files	21 Aug 2008 15:53:00 -0000	1.10
+++ Completion/Unix/Type/_files	17 Aug 2009 21:42:03 -0000
@@ -1,7 +1,7 @@
 #compdef -redirect-,-default-,-default-
 
 local opts tmp glob pat pats expl tag i def descr end ign ret=1 match tried
-local type sdef
+local type sdef ignvars ignvar
 
 zparseopts -a opts \
     '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
@@ -18,14 +18,18 @@
 fi
 tmp=$opts[(I)-F]
 if (( tmp )); then
-  ign=( $=opts[tmp+1] )
-  if [[ $ign = _comp_ignore ]]; then
+  ignvars=($=opts[tmp+1])
+  if [[ $ignvars = _comp_ignore ]]; then
     ign=( $_comp_ignore )
   else
+    ign=()
+    for ignvar in $ignvars; do
+      ign+=(${(P)ignvar})
+    done
     opts[tmp+1]=_comp_ignore
   fi
 else
-  ign=
+  ign=()
 fi
 
 if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then


-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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