diff options
-rw-r--r-- | Completion/Debian/_apt-cache | 40 | ||||
-rw-r--r-- | Completion/Debian/_apt-get | 139 | ||||
-rw-r--r-- | Completion/Debian/_apt_arguments | 381 |
3 files changed, 320 insertions, 240 deletions
diff --git a/Completion/Debian/_apt-cache b/Completion/Debian/_apt-cache new file mode 100644 index 000000000..79fab7aef --- /dev/null +++ b/Completion/Debian/_apt-cache @@ -0,0 +1,40 @@ +#compdef apt-cache + +_apt_arguments _apt-cache_sm \ + -h,--help:bool \ + -v,--version:bool \ + -p,--pkg-cache:'_files "$expl_pkg_cache[@]"' \ + -s,--src-cache:'_files "$expl_src_cache[@]"' \ + -q,--quiet:intlevel \ + -i,--important:bool \ + -f,--full:bool \ + --name-only:bool \ + -c,--config-file:configfile \ + -o,--option:arbitem \ + -- \ + \( \ + /$'help\0' \| \ + /$'add\0' /$'[^\0]#\0' !'_files' \# \| \ + /$'gencaches\0' \| \ + /$'showpkg\0' /$'[^\0]#\0' !'_deb_packages avail "$expl_packages[@]"' \# \| \ + /$'stats\0' \| \ + /$'dump\0' \| \ + /$'dumpavail\0' \| \ + /$'unmet\0' \| \ + /$'check\0' \| \ + /$'search\0' \| \ + /$'show\0' \| \ + /"[]" !'compadd "$expl_action[@]" help add gencaches showpkg stats dump dumpavail unmet check search show' \ + \) + +_apt-cache () { + local expl_action expl_packages expl_pkg_cache expl_src_cache + _description expl_action action + _description expl_packages 'package' + _description expl_pkg_cache 'package cache' + _description expl_src_cache 'source cache' + + _apt-cache_sm +} + +_apt-cache "$@" diff --git a/Completion/Debian/_apt-get b/Completion/Debian/_apt-get index 981cb54c8..1b3016e04 100644 --- a/Completion/Debian/_apt-get +++ b/Completion/Debian/_apt-get @@ -1,117 +1,44 @@ #compdef apt-get -local short_bool short_intlevel short_configfile short_arbitem -local long_bool long_intlevel long_configfile long_arbitem -local action - -short_bool=(h v d b s y f u m) -short_intlevel=(q) -short_configfile=(c) -short_arbitem=(o) - -long_bool=(help version download-only compile build simulate just-print recon - no-act yes assume-yes fix-broken show-upgraded ignore-missing no-download - fix-missing ignore-hold no-upgrade force-yes print-uris) -long_intlevel=(quiet silent) -long_configfile=(config-file) -long_arbitem=(option) - -action=(update upgrade install remove dist-upgrade dselect-upgrade clean - autoclean check source help) - -comp_action='compadd "$expl_action[@]" '"$action" - -regex_action=( - \( - /$'update\0' \| - /$'upgrade\0' \| - /$'install\0' /$'[^\0]#\0' !'_deb_packages uninstalled "$expl_packages[@]" || _deb_packages installed "$expl_packages[@]" ' \# \| - /$'remove\0' /$'[^\0]#\0' !'_deb_packages installed "$expl_packages[@]"' \# \| - /$'dist-upgrade\0' \| - /$'dselect-upgrade\0' \| - /$'clean\0' \| - /$'autoclean\0' \| - /$'check\0' \| - /$'source\0' /$'[^\0]#\0' !'_deb_packages avail "$expl_packages[@]"' \# \| - /$'help\0' \| - /"[]" !"$comp_action" +_apt_arguments _apt-get_sm \ + -h,--help:bool \ + -v,--version:bool \ + -q,--quiet,--silent:intlevel \ + -d,--download-only:bool \ + -b,--compile,--build:bool \ + -s,--simulate,--just-print,--recon,--no-act:bool \ + -y,--yes,--assume-yes:bool \ + -f,--fix-broken:bool \ + -u,--show-upgraded:bool \ + -m,--ignore-missing,--fix-missing:bool \ + --no-download:bool \ + --ignore-hold:bool \ + --no-upgrade:bool \ + --force-yes:bool \ + --print-uris:bool \ + -c,--config-file:configfile \ + -o,--option:arbitem \ + -- \ + \( \ + /$'update\0' \| \ + /$'upgrade\0' \| \ + /$'install\0' /$'[^\0]#\0' !'_deb_packages uninstalled "$expl_packages[@]" || _deb_packages installed "$expl_packages[@]" ' \# \| \ + /$'remove\0' /$'[^\0]#\0' !'_deb_packages installed "$expl_packages[@]"' \# \| \ + /$'dist-upgrade\0' \| \ + /$'dselect-upgrade\0' \| \ + /$'clean\0' \| \ + /$'autoclean\0' \| \ + /$'check\0' \| \ + /$'source\0' /$'[^\0]#\0' !'_deb_packages avail "$expl_packages[@]"' \# \| \ + /$'help\0' \| \ + /"[]" !'compadd "$expl_action[@]" update upgrade install remove dist-upgrade dselect-upgrade clean autoclean check source help' \ \) -) - -_apt_arguments _apt-get_sm "$regex_action[@]" _apt-get () { - local tmp1 tmp2 - local expl_action expl_opt expl_bool expl_configfile expl_packages + local expl_action expl_packages _description expl_action action - _description expl_opt option - _description expl_bool 'bool value' - _description expl_configfile 'config file' _description expl_packages 'package' - typeset -A options short_to_option long_to_option - - options=( - help 1 - version 1 - quiet -1 - download-only 1 - compile 1 - simulate 1 - assume-yes 1 - fix-broken 1 - show-upgraded 1 - no-download 1 - fix-missing 1 - ignore-hold 1 - no-upgrade 1 - force-yes 1 - print-uris 1 - config-file 1 - option -1 - ) - - short_to_option=( - h help - v version - q quiet - d download-only - b compile - s simulate - y assume-yes - f fix-broken - u show-upgraded - m fix-missing - c config-file - o option - ) - - long_to_option=( - help help - version version - quiet quiet - silent quiet - download-only download-only - compile compile - build compile - simulate simulate - just-print simulate - recon simulate - no-act simulate - yes assume-yes - assume-yes assume-yes - fix-broken fix-broken - show-upgraded show-upgraded - ignore-missing fix-missing - no-download no-download - ignore-hold ignore-hold - no-upgrade no-upgrade - force-yes force-yes - print-uris print-uris - config-file config-file - option option - ) - _apt-get_sm } diff --git a/Completion/Debian/_apt_arguments b/Completion/Debian/_apt_arguments index b97a92852..c06ad17d6 100644 --- a/Completion/Debian/_apt_arguments +++ b/Completion/Debian/_apt_arguments @@ -1,28 +1,54 @@ #autoload -# short_bool=(h v d b s y f u m) -# short_intlevel=(q) -# short_configfile=(c) -# short_arbitem=(o) -# -# long_bool=(help version download-only compile build simulate just-print recon -# no-act yes assume-yes fix-broken show-upgraded ignore-missing no-download -# fix-missing ignore-hold no-upgrade force-yes print-uris) -# long_intlevel=(quiet silent) -# long_configfile=(config-file) -# long_arbitem=(option) - -### +# usage: _apt_arguments funcname option-spec... -- rest-regex local funcname funcname="$1" shift -local short_seq false true bool bool_ __bool_ intlevel word word1 nul -local comp_bool comp_intlevel comp_configfile comp_arbitem comp_long -local regex_short regex_long regex_message regex_action +typeset -A canonicalize options +local short_hasarg short_bool short_intlevel short_configfile short_arbitem +local long_hasarg long_bool long_intlevel long_configfile long_arbitem +local comp_hasarg='' +local opt opts type -regex_action=("$@") +while [[ 0 -lt $# && $1 != -- ]]; do + opts="${1%%:*}" + type="${1#*:}" + + case $type in + bool) options[$opts]=1;; + intlevel) options[$opts]=-1;; + configfile) options[$opts]=1;; + arbitem) options[$opts]=-1;; + *) options[$opts]=1 + comp_hasarg="${comp_hasarg}$opts) $type;; +" + type=hasarg;; + esac + + for opt in ${(s:,:)=opts}; do + canonicalize[$opt]="$opts" + case $opt in + --*) eval "long_$type=(\$long_$type ${opt#--})";; + -?) eval "short_$type=(\$short_$type ${opt#-})";; + esac + done + shift +done + +# skip -- +[[ 0 -lt $# ]] && shift + +comp_hasarg="\ +case \$current_option in +${comp_hasarg}esac" + +local short_seq false true bool __bool_ intlevel word word1 nul +local comp_bool comp_intlevel comp_configfile comp_arbitem comp_long comp_opt +local regex_short regex_long regex_all + +regex_all=("$@") short_seq="(${(j:|:)short_bool}|${(j:|:)short_intlevel})#" @@ -30,14 +56,12 @@ false=(no false without off disable) true=(yes true with on enable) bool=($false $true) -bool_=(${^bool}-) -__bool_=(--$^bool_) +__bool_=(--${^bool}-) intlevel='[0-9]##' word=$'[^\0]#\0' word1=$'[^\0]##\0' - nul=$'\0' comp_bool='compadd "$expl_bool[@]" '"$bool" @@ -45,186 +69,275 @@ comp_intlevel= #"_message 'intlevel'" comp_configfile='_files "$expl_configfile[@]"' comp_arbitem= #"_message 'Foo::Bar=bar'" -comp_long="\ -tmp1=\${(kj:|:)long_to_option[(R)\${(kj:|:)~options[(R)*~0]}]} -tmp2=(--\${(M)^long_bool:#\$~tmp1} --\${(M)^long_intlevel:#\$~tmp1}) -compadd \"\$expl_opt[@]\" - \$tmp2 -tmp2=(--\${(M)^long_configfile:#\$~tmp1} --\${(M)^long_arbitem:#\$~tmp1}) -compadd \"\$expl_opt[@]\" -S= - \$tmp2 -compadd \"\$expl_opt[@]\" -S '' - $__bool_" - -regex_short=( - %- - \( +comp_short=\ +'if [[ $PREFIX = -'"$short_seq"' ]]; then + apt_consume_short ${PREFIX[2,-1]} + tmp1=(${${(M)${(s:,:)${(kj:,:)options[(R)*~0]}}:#-?}#-}) + tmp2=(-${^tmp1}) + compadd "$expl_opt[@]" -y "($tmp2)" - ${PREFIX}${^tmp1} +elif [[ -z "$PREFIX" ]]; then + compadd "$expl_opt[@]" - ${(M)${(s:,:)${(kj:,:)options[(R)*~0]}}:#-?} +fi' + +comp_long=\ +'tmp1="${(j:|:)${(@)${(@M)${(@s:,:)${(@kj:,:)options[(R)*~0]}}:#--*}#--}}" +tmp2=(--${(M)^long_bool:#$~tmp1} --${(M)^long_intlevel:#$~tmp1}) +compadd "$expl_opt[@]" - $tmp2 +tmp2=(--${(M)^long_hasarg:#$~tmp1} --${(M)^long_configfile:#$~tmp1} --${(M)^long_arbitem:#$~tmp1}) +compadd "$expl_opt[@]" -S= - $tmp2 +compadd "$expl_opt[@]" -S "" - '"$__bool_" + +comp_long_prefix=\ +'tmp1="${(j:|:)${(@)${(@M)${(@s:,:)${(@kj:,:)options[(R)*~0]}}:#--*}#--}}" +tmp2=($_ra_left${(M)^long_bool:#$~tmp1} $_ra_left${(M)^long_intlevel:#$~tmp1}) +compadd "$expl_opt[@]" - $tmp2 +tmp2=($_ra_left${(M)^long_hasarg:#$~tmp1} $_ra_left${(M)^long_configfile:#$~tmp1} $_ra_left${(M)^long_arbitem:#$~tmp1}) +compadd "$expl_opt[@]" -S= - $tmp2 +tmp1="${(j:|:)${(@)${(@M)${(@s:,:)${(@kj:,:)options[(R)*~0]}}:#-?}#-}}" +tmp2=($_ra_left${(M)^short_bool:#$~tmp1} $_ra_left${(M)^short_intlevel:#$~tmp1}) +compadd "$expl_opt[@]" - $tmp2 +tmp2=($_ra_left${(M)^short_hasarg:#$~tmp1} $_ra_left${(M)^short_configfile:#$~tmp1} $_ra_left${(M)^short_arbitem:#$~tmp1}) +compadd "$expl_opt[@]" -S= - $tmp2' + +comp_opt='[[ -prefix - || -z "$compconfig[option_prefix]" ]]'" && { $comp_short; $comp_long }" + +regex_short=() +regex_long=() +regex_long_prefix=() + +if (( $#short_hasarg )); then + regex_short=("$regex_short[@]" + /"$short_seq(${(j:|:)short_hasarg})(=|)" + -'apt_consume_short ${_ra_match%=}; current_option=${canonicalize[-${${_ra_match%=}[-1]}]}' + \( /"$word1" !"$comp_hasarg" \| /"$nul" /"$word" !"$comp_hasarg" \) \| + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)short_hasarg})$nul" + -'apt_consume_short ${_ra_match[-2]}; current_option=${canonicalize[-${${_ra_match%$nul}[-1]}]}' + /"$word" !"$comp_hasarg" \| + /"(${(j:|:)short_hasarg})=" + -'apt_consume_short ${_ra_match[-2]}; current_option=${canonicalize[-${${_ra_match%=}[-1]}]}' + \( /"$word1" !"$comp_hasarg" \| /"$nul" /"$word" !"$comp_hasarg" \) \| + ) +fi + +if (( $#short_bool )); then + regex_short=("$regex_short[@]" /"$short_seq(${(j:|:)short_bool})($nul(${(j:|:)bool})|(${(j:|:)bool})|)$nul" -"apt_consume_short \${_ra_match%%($nul(${(j:|:)bool})|(${(j:|:)bool})|)$nul}" \| /"$short_seq(${(j:|:)short_bool})=" -"apt_consume_short \${_ra_match%=}" \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \| + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)short_bool})=" + -"apt_consume_short \${_ra_match[-2]}" + \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \| + /"(${(j:|:)short_bool})$nul" + -"apt_consume_short \${_ra_match[-2]}" + /"((${(j:|:)bool})$nul|)" !"$comp_bool" \| + ) +fi + +if (( $#short_intlevel )); then + regex_short=("$regex_short[@]" /"$short_seq(${(j:|:)short_intlevel})($nul$intlevel|$intlevel|)$nul" -"apt_consume_short \${_ra_match%%($nul$intlevel|$intlevel|)$nul}" \| /"$short_seq(${(j:|:)short_intlevel})=" -"apt_consume_short \${_ra_match%=}" \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \| + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)short_intlevel})=" + -"apt_consume_short \${_ra_match[-2]}" + \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \| + /"(${(j:|:)short_intlevel})$nul" + -"apt_consume_short \${_ra_match[-2]}" + /"($intlevel$nul|)" !"$comp_intlevel" \| + ) +fi + +if (( $#short_configfile )); then + regex_short=("$regex_short[@]" /"$short_seq(${(j:|:)short_configfile})(=|)" -"apt_consume_short \${_ra_match%=}" \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \| + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)short_configfile})$nul" + -"apt_consume_short \${_ra_match[-2]}" + /"$word" !"$comp_configfile" \| + /"(${(j:|:)short_configfile})=" + -"apt_consume_short \${_ra_match[-2]}" + \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \| + ) +fi + +if (( $#short_arbitem )); then + regex_short=("$regex_short[@]" /"$short_seq(${(j:|:)short_arbitem})(=|)" -"apt_consume_short \${_ra_match%=}" \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \| - /"[]" !"{ - if [[ \$PREFIX = -$short_seq ]]; then - apt_consume_short \${PREFIX[2,-1]} - tmp1=(\${(k)short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]}) - tmp2=(-\${^tmp1}) - compadd \"\$expl_opt[@]\" -y \"(\$tmp2)\" - \${PREFIX}\${^tmp1} - fi - $comp_long - }" - \) -) + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)short_arbitem})$nul" + -"apt_consume_short \${_ra_match[-2]}" + /"$word" !"$comp_arbitem" \| + /"(${(j:|:)short_arbitem})=" + -"apt_consume_short \${_ra_match[-2]}" + \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \| + ) +fi -regex_long=( - %-- - \( +if (( $#long_hasarg )); then + regex_long=("$regex_long[@]" + /"(${(j:|:)long_hasarg})$nul" + -"apt_consume_long \${_ra_match%$nul}; current_option=\${canonicalize[--\${_ra_match%$nul}]}" + /"$word" !"$comp_hasarg" \| + /"(${(j:|:)long_hasarg})=" + -"apt_consume_long \${_ra_match%=}; current_option=\${canonicalize[--\${_ra_match%=}]}" + \( /"$word1" !"$comp_hasarg" \| /"$nul" /"$word" !"$comp_hasarg" \) \| + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)long_hasarg})$nul" + -"apt_consume_long \${_ra_match%$nul}; current_option=\${canonicalize[--\${_ra_match%$nul}]}" + /"$word" !"$comp_hasarg" \| + /"(${(j:|:)long_hasarg})=" + -"apt_consume_long \${_ra_match%=}; current_option=\${canonicalize[--\${_ra_match%=}]}" + \( /"$word1" !"$comp_hasarg" \| /"$nul" /"$word" !"$comp_hasarg" \) \| + ) +fi + +if (( $#long_bool )); then + regex_long=("$regex_long[@]" /"(${(j:|:)long_bool})=" -"apt_consume_long \${_ra_match%=}" \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \| /"(${(j:|:)long_bool})$nul" -"apt_consume_long \${_ra_match%$nul}" /"((${(j:|:)bool})$nul|)" !"$comp_bool" \| + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)long_bool})=" + -"apt_consume_long \${_ra_match%=}" + \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \| + /"(${(j:|:)long_bool})$nul" + -"apt_consume_long \${_ra_match%$nul}" + /"((${(j:|:)bool})$nul|)" !"$comp_bool" \| + ) +fi + +if (( $#long_intlevel )); then + regex_long=("$regex_long[@]" /"(${(j:|:)long_intlevel})=" -"apt_consume_long \${_ra_match%=}" \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \| /"(${(j:|:)long_intlevel})$nul" -"apt_consume_long \${_ra_match%$nul}" /"($intlevel$nul|)" !"$comp_intlevel" \| + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)long_intlevel})$nul" + -"apt_consume_long \${_ra_match%$nul}" + /"$intlevel" !"$comp_intlevel" /"$nul" \| + /"(${(j:|:)long_intlevel})=" + -"apt_consume_long \${_ra_match%=}" + \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \| + /"(${(j:|:)long_intlevel})$nul" + -"apt_consume_long \${_ra_match%$nul}" + /"($intlevel$nul|)" !"$comp_intlevel" \| + ) +fi + +if (( $#long_configfile )); then + regex_long=("$regex_long[@]" + /"(${(j:|:)long_configfile})$nul" + -"apt_consume_long \${_ra_match%$nul}" + /"$word" !"$comp_configfile" \| + /"(${(j:|:)long_configfile})=" + -"apt_consume_long \${_ra_match%=}" + \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \| + ) + regex_long_prefix=("$regex_long_prefix[@]" /"(${(j:|:)long_configfile})$nul" -"apt_consume_long \${_ra_match%$nul}" /"$word" !"$comp_configfile" \| /"(${(j:|:)long_configfile})=" -"apt_consume_long \${_ra_match%=}" \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \| + ) +fi + +if (( $#long_arbitem )); then + regex_long=("$regex_long[@]" /"(${(j:|:)long_arbitem})$nul" -"apt_consume_long \${_ra_match%$nul}" /"$word" !"$comp_arbitem" \| /"(${(j:|:)long_arbitem})=" -"apt_consume_long \${_ra_match%=}" \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \| - %"(${(j:|:)bool})-" - \( - /"(${(j:|:)long_bool})=" - -"apt_consume_long \${_ra_match%=}" - \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \| - /"(${(j:|:)long_bool})$nul" - -"apt_consume_long \${_ra_match%$nul}" - /"((${(j:|:)bool})$nul|)" !"$comp_bool" \| - /"(${(j:|:)long_intlevel})$nul" - -"apt_consume_long \${_ra_match%$nul}" - /"$intlevel" !"$comp_intlevel" /"$nul" \| - /"(${(j:|:)long_intlevel})=" - -"apt_consume_long \${_ra_match%=}" - \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \| - /"(${(j:|:)long_intlevel})$nul" - -"apt_consume_long \${_ra_match%$nul}" - /"($intlevel$nul|)" !"$comp_intlevel" \| - /"(${(j:|:)long_configfile})$nul" - -"apt_consume_long \${_ra_match%$nul}" - /"$word" !"$comp_configfile" \| - /"(${(j:|:)long_configfile})=" - -"apt_consume_long \${_ra_match%=}" - \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \| - /"(${(j:|:)long_arbitem})$nul" - -"apt_consume_long \${_ra_match%$nul}" - /"$word" !"$comp_arbitem" \| - /"(${(j:|:)long_arbitem})=" - -"apt_consume_long \${_ra_match%=}" - \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \| - /"(${(j:|:)short_bool})=" - -"apt_consume_short \${_ra_match[-2]}" - \( /"$word1" !"$comp_bool" \| /"$nul" /"$word" !"$comp_bool" \) \| - /"(${(j:|:)short_bool})$nul" - -"apt_consume_short \${_ra_match[-2]}" - /"((${(j:|:)bool})$nul|)" !"$comp_bool" \| - /"(${(j:|:)short_intlevel})=" - -"apt_consume_short \${_ra_match[-2]}" - \( /"$word1" !"$comp_intlevel" \| /"$nul" /"$word" !"$comp_intlevel" \) \| - /"(${(j:|:)short_intlevel})$nul" - -"apt_consume_short \${_ra_match[-2]}" - /"($intlevel$nul|)" !"$comp_intlevel" \| - /"(${(j:|:)short_configfile})$nul" - -"apt_consume_short \${_ra_match[-2]}" - /"$word" !"$comp_configfile" \| - /"(${(j:|:)short_configfile})=" - -"apt_consume_short \${_ra_match[-2]}" - \( /"$word1" !"$comp_configfile" \| /"$nul" /"$word" !"$comp_configfile" \) \| - /"(${(j:|:)short_arbitem})$nul" - -"apt_consume_short \${_ra_match[-2]}" - /"$word" !"$comp_arbitem" \| - /"(${(j:|:)short_arbitem})=" - -"apt_consume_short \${_ra_match[-2]}" - \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \| - /"[]" !"{ tmp1=\${(kj:|:)long_to_option[(R)\${(kj:|:)~options[(R)*~0]}]} - tmp2=(\$_ra_left\${(M)^long_bool:#\$~tmp1} \$_ra_left\${(M)^long_intlevel:#\$~tmp1}) - compadd \"\$expl_opt[@]\" - \$tmp2 - tmp2=(\$_ra_left\${(M)^long_configfile:#\$~tmp1} \$_ra_left\${(M)^long_arbitem:#\$~tmp1}) - compadd \"\$expl_opt[@]\" -S= - \$tmp2 - tmp1=\${(kj:|:)short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]} - tmp2=(\$_ra_left\${(M)^short_bool:#\$~tmp1} \$_ra_left\${(M)^short_intlevel:#\$~tmp1}) - compadd \"\$expl_opt[@]\" - \$tmp2 - tmp2=(\$_ra_left\${(M)^short_configfile:#\$~tmp1} \$_ra_left\${(M)^short_arbitem:#\$~tmp1}) - compadd \"\$expl_opt[@]\" -S= - \$tmp2 - }" - \) \| - /"[]" !"{ - $comp_long - }" - \) -) + ) + regex_long_prefix=("$regex_long_prefix[@]" + /"(${(j:|:)long_arbitem})$nul" + -"apt_consume_long \${_ra_match%$nul}" + /"$word" !"$comp_arbitem" \| + /"(${(j:|:)long_arbitem})=" + -"apt_consume_long \${_ra_match%=}" + \( /"$word1" !"$comp_arbitem" \| /"$nul" /"$word" !"$comp_arbitem" \) \| + ) +fi -regex_message=( - /"[]" !"[[ -prefix - || -z \"\$compconfig[option_prefix]\" ]] && { - if [[ \$PREFIX = -$short_seq ]]; then - apt_consume_short \${PREFIX[2,-1]} - tmp1=(\${(k)short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]}) - tmp2=(-\${^tmp1}) - compadd \"\$expl_opt[@]\" -y \"(\$tmp2)\" - \${PREFIX}\${^tmp1} - elif [[ -z "\$PREFIX" ]]; then - tmp1=(-\${(k)^short_to_option[(R)\${(kj:|:)~options[(R)*~0]}]}) - compadd \"\$expl_opt[@]\" - \$tmp1 - fi - $comp_long - }" +regex_all=( + /"$word" + \( %-- \( "$regex_long[@]" + %"(${(j:|:)bool})-" + \( "$regex_long_prefix[@]" /"[]" !"$comp_long_prefix" \) \| + /"[]" !"$comp_long" \) \| + %- \( "$regex_short[@]" /"[]" !"$comp_short; $comp_long" \) \| + /"[]" !"$comp_opt" \) \# + "$regex_all[@]" ) apt_consume_short () { local short opt for short in ${(s::)1}; do - opt="$short_to_option[$short]" + opt="$canonicalize[-$short]" (( 0 < options[$opt] && options[$opt]-- )) done } apt_consume_long () { local long opt - opt="$long_to_option[$1]" + opt="$canonicalize[--$1]" (( 0 < options[$opt] && options[$opt]-- )) } -_regex_arguments "${funcname}_sm" /"$word" \( "$regex_long[@]" \| "$regex_short[@]" \| "$regex_message[@]" \) \# "$regex_action[@]" +_regex_arguments "${funcname}_sm" "$regex_all[@]" eval "$funcname () { - local short_bool short_intlevel short_configfile short_arbitem - local long_bool long_intlevel long_configfile long_arbitem + typeset -A canonicalize options + canonicalize=(${(kv)canonicalize}) + options=(${(kv)options}) + + local short_hasarg short_bool short_intlevel short_configfile short_arbitem + local long_hasarg long_bool long_intlevel long_configfile long_arbitem + short_hasarg=($short_hasarg) short_bool=($short_bool) short_intlevel=($short_intlevel) short_configfile=($short_configfile) short_arbitem=($short_arbitem) + long_hasarg=($long_hasarg) long_bool=($long_bool) long_intlevel=($long_intlevel) long_configfile=($long_configfile) long_arbitem=($long_arbitem) + local expl_opt expl_bool expl_configfile + _description expl_opt option + _description expl_bool 'bool value' + _description expl_configfile 'config file' + + local current_option tmp1 tmp2 + ${funcname}_sm }" - |