about summary refs log tree commit diff
path: root/Completion/Base/_arguments
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Base/_arguments')
-rw-r--r--Completion/Base/_arguments41
1 files changed, 28 insertions, 13 deletions
diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments
index 68b52eef4..fbc7d7875 100644
--- a/Completion/Base/_arguments
+++ b/Completion/Base/_arguments
@@ -3,7 +3,7 @@
 # Complete the arguments of the current command according to the
 # descriptions given as arguments to this function.
 
-local long cmd="$words[1]" descr mesg
+local long cmd="$words[1]" descr mesg subopts
 
 long=$argv[(I)--]
 if (( long )); then
@@ -151,17 +151,30 @@ if (( long )); then
   set -- "$tmpargv[@]" "${(@P)name}"
 fi
 
+if [[ "$1" = -O?* ]]; then
+  subopts=( "${(@P)1[3,-1]}" )
+  shift
+elif [[ "$1" = -O ]]; then
+  subopts=( "${(@P)1}" )
+  shift 2
+else
+  subopts=()
+fi
+
 if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
   local nm="$compstate[nmatches]" action noargs aret expl local
   local next direct odirect equal single match matched ws tmp1 tmp2
-  local opts
+  local opts _sub_context oldsc="${_sub_context}"
 
   if comparguments -D descr action; then
+    comparguments -C _sub_context
+    _sub_context="${oldsc}:${oldsc:+${oldsc}-}${_sub_context}"
+
     if comparguments -O next direct odirect equal; then
       opts=yes
-      _tags argument option
+      _tags "${oldsc}:any" arguments options
     else
-      _tags argument
+      _tags "${oldsc}:any" arguments
     fi
   else
     if comparguments -a; then
@@ -172,12 +185,12 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
     comparguments -O next direct odirect equal || return 1
 
     opts=yes
-    _tags option
+    _tags "${oldsc}:any" options
   fi
 
   while _tags; do
     while true; do
-      if [[ -n "$matched" ]] || _requested argument; then
+      if [[ -n "$matched" ]] || _requested arguments; then
         _description expl "$descr"
 
         if [[ "$action" = -\>* ]]; then
@@ -207,13 +220,13 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
 
             eval ws\=\( "${action[3,-3]}" \)
 
-            _describe -c "$cmd" "$descr" ws -M "$match"
+            _describe -c "$cmd" "$descr" ws -M "$match" "$subopts[@]"
 
           elif [[ "$action" = \(*\) ]]; then
 
             # Anything inside `(...)' is added directly.
 
-            compadd "$expl[@]" - ${=action[2,-2]}
+            compadd "$subopts[@]" "$expl[@]" - ${=action[2,-2]}
           elif [[ "$action" = \{*\} ]]; then
 
             # A string in braces is evaluated.
@@ -230,12 +243,13 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
             # Otherwise we call it with the description-arguments built above.
 
             action=( $=action )
-            ${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]}
+            ${(e)action[1]} "$subopts[@]" "$expl[@]" ${(e)~action[2,-1]}
           fi
         fi
       fi
-      if [[ -z "$matched" ]] && _requested option &&
-          { ! _style option prefix || [[ "$PREFIX" = [-+]* ]] } ; then
+      if [[ -z "$matched" ]] && _requested options &&
+          { ! _style options prefix-needed yes ||
+            [[ "$PREFIX" = [-+]* ]] } ; then
         comparguments -M match
 
         if comparguments -s single; then
@@ -267,7 +281,7 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
       fi
       if [[ -n "$opts" && -z "$aret$matched" &&
             nm -ne compstate[nmatches] ]] &&
-          _requested argument; then
+          _requested arguments; then
 
         local prefix suffix
 
@@ -282,7 +296,8 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then
 	  SUFFIX="$suffix"
 	  IPREFIX="${IPREFIX}${equal[1]%%:*}="
 	  matched=yes
-	  comparguments -L "$equal[1]" descr action
+	  comparguments -L "$equal[1]" descr action _sub_context
+          _sub_context="${oldsc}:${oldsc+${oldsc}-}${_sub_context}"
 	  continue
         fi
       fi