diff options
Diffstat (limited to 'Completion/Base')
-rw-r--r-- | Completion/Base/.distfiles | 3 | ||||
-rw-r--r-- | Completion/Base/_complete_opts | 88 | ||||
-rw-r--r-- | Completion/Base/_first | 4 |
3 files changed, 92 insertions, 3 deletions
diff --git a/Completion/Base/.distfiles b/Completion/Base/.distfiles index ef1e9df73..c2cd2b58a 100644 --- a/Completion/Base/.distfiles +++ b/Completion/Base/.distfiles @@ -1,6 +1,7 @@ DISTFILES_SRC=' .distfiles - _brace_parameter _command_names _condition _default _equal _first + _brace_parameter _command_names _complete_opts + _condition _default _equal _first _long_options _math _parameter _precommand _redirect _subscript _tilde _vars ' diff --git a/Completion/Base/_complete_opts b/Completion/Base/_complete_opts new file mode 100644 index 000000000..689e13e22 --- /dev/null +++ b/Completion/Base/_complete_opts @@ -0,0 +1,88 @@ +#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 + compadd - -${(k)^option_pairs:gs/://} + false +else + true +fi diff --git a/Completion/Base/_first b/Completion/Base/_first index 8b4da019d..c33e91ff0 100644 --- a/Completion/Base/_first +++ b/Completion/Base/_first @@ -53,9 +53,9 @@ # if compgen -X "%Bhistory ($n):%b" -Q -H $(( i*10 )) ''; then # # We have found at least one matching word, so we switch # # on menu-completion and make sure that no other -# # completion function is called by setting _comp_skip. +# # completion function is called by setting _compskip. # compstate[insert]=menu -# _comp_skip=1 +# _compskip=1 # return # fi # (( i++ )) |