about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-07-27 08:30:53 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-07-27 08:30:53 +0000
commite083f0aa5c1db97869a6bd57cce9a5f2075030e6 (patch)
tree4d99c705384c28af61e1feba0c9f707184dff36d
parent43df8cd0726e06cba2b59f077f4e0826d764c237 (diff)
downloadzsh-e083f0aa5c1db97869a6bd57cce9a5f2075030e6.tar.gz
zsh-e083f0aa5c1db97869a6bd57cce9a5f2075030e6.tar.xz
zsh-e083f0aa5c1db97869a6bd57cce9a5f2075030e6.zip
zsh-workers:7278
-rw-r--r--Completion/Base/_complete_opts90
1 files changed, 90 insertions, 0 deletions
diff --git a/Completion/Base/_complete_opts b/Completion/Base/_complete_opts
new file mode 100644
index 000000000..c27a8869f
--- /dev/null
+++ b/Completion/Base/_complete_opts
@@ -0,0 +1,90 @@
+#autoload
+
+# Usage:
+#  _complete_opts H '' f '_files'
+
+emulate -L zsh
+setopt extendedglob
+
+local done=yes
+
+typeset -A option_pairs
+option_pairs=("$@")
+typeset -a no_arg with_arg opt_arg
+no_arg=($option_pairs[(I)?])
+opt_arg=($option_pairs[(I)?::]:s/:://)
+with_arg=($option_pairs[(I)?:]:s/:// $opt_arg)
+
+case "${#no_arg}-${#with_arg}" in
+  0-0)
+    if [[ x$PREFIX = x-* ]]; then
+      compadd -nQ - "$PREFIX$SUFFIX"
+    else
+      done=''
+    fi
+    ;;
+
+  0-*)
+    if [[ x$PREFIX = x- ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      compadd $with_arg
+    elif [[ x$PREFIX = x-[${(j::)with_arg}] ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$PREFIX = x-[${(j::)with_arg}]* ]]; then
+      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
+      IPREFIX="$IPREFIX$p"
+      PREFIX="$PREFIX[$#p + 1,-1]"
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$words[$CURRENT-1] = x-[${(j::)with_arg}] ]]; then
+      local p="$words[$CURRENT - 1]"
+      eval $option_pairs[$p[-1]:]
+    else
+      done=''
+    fi
+    ;;
+
+  *-0)
+    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      compadd $no_arg
+    else
+      done=''
+    fi
+    ;;
+
+  *-*)
+    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      compadd $no_arg
+      compadd $with_arg
+    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}]* ]]; then
+      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
+      IPREFIX="$IPREFIX$p"
+      PREFIX="$PREFIX[$#p + 1,-1]"
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$words[$CURRENT-1] = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
+      local p="$words[$CURRENT - 1]"
+      eval $option_pairs[$p[-1]:]
+    else
+      done=''
+    fi
+    ;;
+esac
+
+if [[ -z "$done" ]]; then
+  if (( $+complete_opts_verbose )); then
+    compadd - -${(k)^option_pairs:gs/://}
+  fi
+  false
+else
+  true
+fi