about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2015-03-07 15:31:14 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2015-03-09 20:01:09 +0000
commit69ada95acd9cb5c5ea51277f23739affe13cc1fb (patch)
tree174f598d6bdb87fe232f446b13aa625bcfa1e646
parentc1eda67909404538addb932203088cada148f9d5 (diff)
downloadzsh-69ada95acd9cb5c5ea51277f23739affe13cc1fb.tar.gz
zsh-69ada95acd9cb5c5ea51277f23739affe13cc1fb.tar.xz
zsh-69ada95acd9cb5c5ea51277f23739affe13cc1fb.zip
34693: sudo completion: Don't false positive 'sudo -e' detection
-rw-r--r--ChangeLog3
-rw-r--r--Completion/Unix/Command/_sudo9
2 files changed, 11 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index c99f726b0..109027b34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-03-09  Daniel Shahaf  <d.s@daniel.shahaf.name>
 
+	* 34693: Completion/Unix/Command/_sudo: sudo completion: Don't
+	false positive 'sudo -e' detection
+
 	* 34693: Completion/Linux/Command/_strace: _strace: Fix variable
 	leakage of $sys_calls
 
diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo
index ee238b462..63ac37f62 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+=(