>From 8baf05d0ad7ea482df6329da13c67695085a0d87 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 7 Mar 2015 15:31:14 +0000 Subject: [PATCH 2/2] sudo completion: Don't false positive 'sudo -e' detection --- Completion/Unix/Command/_sudo | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo index ee238b4..63ac37f 100644 --- a/Completion/Unix/Command/_sudo +++ b/Completion/Unix/Command/_sudo @@ -1,5 +1,7 @@ #compdef sudo sudoedit +setopt localoptions extended_glob + local environ e local -a args @@ -29,7 +31,12 @@ args=( '(-v --validate)'{-v,--validate}"[update user's timestamp without running a command]" ) -if [[ $service = sudoedit || -n ${words[(r)-e]} ]]; then +# Does -e appears before the first word that doesn't begin with a hyphen? +# The way (i) works in subscripts, the test will always be true if all the +# words begin with a hyphen. +# +# TODO: use _arguments' $opt_args to detect the cases '-u jrandom -e' and '-Ae' +if [[ $service = sudoedit ]] || (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] )) ; then args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' ) else args+=( -- 1.9.1