From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17856 invoked by alias); 5 Jan 2014 13:48:52 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32231 Received: (qmail 4512 invoked from network); 5 Jan 2014 13:48:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Biglobe-Sender: From: "Jun T." Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: [PATCH] _chmod: use $line[1] instead of $words[2] to access the mode Message-Id: <91188AF3-FD51-4C2D-AB3A-8F6DE1FBF658@kba.biglobe.ne.jp> Date: Sun, 5 Jan 2014 21:52:56 +0900 To: zsh-workers@zsh.org Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) X-Mailer: Apple Mail (2.1827) The following completes only files which don't have write permission by the user: $ chmod u+w But with one or more options before the 'mode', e.g., $ chmod -v u+w 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