about summary refs log tree commit diff
path: root/Completion/Core/_alternative
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Core/_alternative')
-rw-r--r--Completion/Core/_alternative45
1 files changed, 28 insertions, 17 deletions
diff --git a/Completion/Core/_alternative b/Completion/Core/_alternative
index 158f3a07a..b038aa8a4 100644
--- a/Completion/Core/_alternative
+++ b/Completion/Core/_alternative
@@ -1,19 +1,23 @@
 #autoload
 
-local tags def expl descr action mesgs nm="$compstack[nmatches]"
-local context
+local tags def expl descr action mesgs nm="$compstate[nmatches]" subopts
+local opt curcontext="$curcontext"
+
+subopts=()
+while getopts 'O:C:' opt; do
+  case "$opt" in
+  O) subopts=( "${(@P)OPTARG}" ) ;;
+  C) curcontext="${curcontext%:*}:$OPTARG" ;;
+  esac
+done
+
+shift OPTIND-1
 
-if [[ "$1" = -C?* ]]; then
-  context="${1[3,-1]}"
-  shift
-elif [[ "$1" = -C ]]; then
-  context="$2"
-  shift 2
-fi
+[[ "$1" = -(|-) ]] && shift
 
 mesgs=()
 
-_tags -C "$context" "${(@)argv%%:*}"
+_tags "${(@)argv%%:*}"
 
 while _tags; do
   for def; do
@@ -21,7 +25,7 @@ while _tags; do
       descr="${${def#*:}%%:*}"
       action="${def#*:*:}"
 
-      _description expl "$descr"
+      _description "${def%%:*}" expl "$descr"
 
       if [[ "$action" = \ # ]]; then
 
@@ -35,28 +39,35 @@ while _tags; do
 
         eval ws\=\( "${action[3,-3]}" \)
 
-        _describe "$descr" ws -M 'r:|[_-]=* r:|=*'
+        _describe "$descr" ws -M 'r:|[_-]=* r:|=*' "$subopts[@]"
       elif [[ "$action" = \(*\) ]]; then
 
         # Anything inside `(...)' is added directly.
 
-        compadd "$expl[@]" - ${=action[2,-2]}
+        _all_labels "${def%%:*}" expl "$descr" \
+            compadd "$subopts[@]" - ${=action[2,-2]}
       elif [[ "$action" = \{*\} ]]; then
 
         # A string in braces is evaluated.
 
-        eval "$action[2,-2]"
+        while _next_label "${def%%:*}" expl "$descr"; do
+          eval "$action[2,-2]"
+        done
       elif [[ "$action" = \ * ]]; then
 
         # If the action starts with a space, we just call it.
 
-        ${(e)=~action}
+        eval "action=( $action )"
+        while _next_label "${def%%:*}" expl "$descr"; do
+          "$action[@]"
+        done
       else
 
         # Otherwise we call it with the description-arguments built above.
 
-        action=( $=action )
-        ${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]}
+        eval "action=( $action )"
+        _all_labels "${def%%:*}" expl "$descr" \
+            "$action[1]" "$subopts[@]" "${(@)action[2,-1]}"
       fi
     fi
   done