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

[PATCH] _chmod: use $line[1] instead of $words[2] to access the mode



The following completes only files which don't have write permission
by the user:

$ chmod u+w <TAB>

But with one or more options before the 'mode', e.g.,

$ chmod -v u+w <TAB>

then it completes *all* files including those which already have write
permission.

This is due to that _chmod uses $words[2] to access the 'mode' on the
command line; I think it should be $line[1].

BTW, man zshcompsys says, in the description of _arguments, 

  During the performance of the action the array `line' will  be  set  to
  the  command  name and normal arguments from the command line, i.e. the
  words from the command line excluding all options and their  arguments.

But it seems $line contains only the 'normal arguments', not including
the 'command name'.



diff --git a/Completion/Unix/Command/_chmod b/Completion/Unix/Command/_chmod
index 6cb310d..5d3cb2c 100644
--- a/Completion/Unix/Command/_chmod
+++ b/Completion/Unix/Command/_chmod
@@ -57,12 +57,12 @@ case "$state" in
       zmodload -F zsh/stat b:zstat 2>/dev/null
       typeset -i8 ref=$(zstat +mode $opt_args[--reference])
       _wanted files expl file _files -g "*(-.^f${ref#??})" && ret=0
-    elif [[ $words[2] = [0-7]## ]]; then
-      _wanted files expl file _files -g "*(-.^f$words[2])" && ret=0
+    elif [[ $line[1] = [0-7]## ]]; then
+      _wanted files expl file _files -g "*(-.^f$line[1])" && ret=0
     else
       local spec who op priv
       local -a specs
-      for spec in ${(s:,:)words[2]}; do
+      for spec in ${(s:,:)line[1]}; do
 	if [[ ${spec#*[+-=]} != [rwxst]## ]]; then
 	  _files && ret=0
 	  return ret




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