From 11ecfb4d94d6aa5dc42156a5e1c57b8d0bfc0223 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Tue, 14 Sep 1999 14:55:37 +0000 Subject: zsh-workers/7827 --- Completion/Base/_arguments | 72 ++++++++++++++++------------------ Completion/Base/_values | 47 +++++++++++------------ Completion/Core/_display | 96 +++++++++++++--------------------------------- Completion/User/_mount | 6 ++- 4 files changed, 84 insertions(+), 137 deletions(-) (limited to 'Completion') diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index a25e8ded1..a8e272cac 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -794,13 +794,9 @@ while true; do eval ws\=\( "${action[3,-3]}" \) if [[ -n "$compconfig[describe_values]" && - "$compconfig[describe_values]" != *\!${cmd}* ]]; then - if _display tmp ws -M 'r:|[_-]=* r:|=*'; then - compadd "$expl[@]" -y tmp - "${(@)ws%%:*}" - else - [[ -n "$matched" ]] && compadd -Q -S -s "$SUFFIX" - "$PREFIX" - _message "$descr" - fi + "$compconfig[describe_values]" != *\!${cmd}* ]] && + _display tmp "$ws[@]"; then + compadd "$expl[@]" -M 'r:|[_-]=* r:|=*' -ld tmp - "${(@)ws%%:*}" else compadd "$expl[@]" - "${(@)ws%%:*}" fi @@ -841,51 +837,47 @@ while true; do if [[ -n "$sopts" && -n "$PREFIX" && "$PREFIX" = [-+]${~soptseq}[$sopts] ]]; then if [[ "$PREFIX" = [-+]${~soptseq1} ]]; then - local dpre="$PREFIX" dsuf="$SUFFIX" - - PREFIX='' - SUFFIX='' if [[ -z "$compconfig[describe_options]" || - "$compconfig[describe_options]" = *\!${cmd}* ]] || - ! _display tmp odescr; then - tmp=( "${dpre[1]}${(@o)^${(@)${(@M)${=:-${(k)opts} ${(k)dopts} ${(k)odopts}}:#[-+]?(|=)}#?}%=}" ) - fi - PREFIX="$dpre" - SUFFIX="$dsuf" - compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -y tmp - \ + "$compconfig[describe_options]" = *\!${cmd}* ]]; then + tmp=( "${PREFIX[1]}${(@)^${(@)${(@M)${=:-${(k)opts} ${(k)dopts} ${(k)odopts}}:#[-+]?(|=)}#?}%=}" ) + compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -d tmp - \ "${PREFIX}${(@k)^opts[(I)${PREFIX[1]}?]#?}" \ "${PREFIX}${(@k)^dopts[(I)${PREFIX[1]}?]#?}" \ "${PREFIX}${(@)^${(@k)odopts[(I)${PREFIX[1]}?(|=)]#?}%=}" && - ret=0 + ret=0 + elif _display tmp "${(@Mo)odescr:#[-+]?:*}"; then + compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -ld tmp - \ + "${PREFIX}${(@)^${(@)${(@Mo)odescr:#[-+]?:*}%%:*}#?}" && ret=0 + else + compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -d tmp - \ + "${PREFIX}${(@)^${(@)${(@Mo)odescr:#[-+]?:*}%%:*}#?}" && ret=0 + fi else # The last option takes an argument in the next word. compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' - "${PREFIX}" && ret=0 fi else - tmp='' if [[ -n "$compconfig[describe_options]" && - "$compconfig[describe_options]" != *\!${cmd}* ]]; then - if _display tmp odescr; then - if (( $#dopts )); then - compadd -n "$expl[@]" -QS '' -M 'r:|[_-]=* r:|=*' -y tmp - \ - "${(@k)dopts}" && ret=0 - compadd -n -J option -Q -M 'r:|[_-]=* r:|=*' - \ - "${(@k)opts}" "${(@k)odopts[(I)*[^=]]}" && ret=0 - compadd -n -J option -QqS= -M 'r:|[_-]=* r:|=*' - \ - "${(@k)odopts[(I)*=]%=}" && ret=0 - elif (( ${(@k)#odopts[(I)*=]} )); then - compadd -n "$expl[@]" -QqS= -M 'r:|[_-]=* r:|=*' -y tmp - \ - "${(@k)odopts[(I)*=]%=}" && ret=0 - compadd -n -J option -Q -M 'r:|[_-]=* r:|=*' - \ - "${(@k)opts}" "${(@k)odopts[(I)*[^=]]}" && ret=0 - else - compadd -n "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -y tmp - \ - "${(@k)opts}" "${(@k)odopts[(I)*[^=]]}" && ret=0 - fi + "$compconfig[describe_options]" != *\!${cmd}* ]] && + _display descr "$odescr[@]"; then + ws=( "${(k)opts[@]}" "${(@k)odopts[(I)*[^=]]}" ) + if (( $#ws )); then + tmp=( "${(@M)descr:#(${(j:|:)~ws}) *}" ) + compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -ld tmp - \ + "$ws[@]" && ret=0 + fi + if (( $#dopts )); then + tmp=( "${(@M)descr:#(${(kj:|:)~dopts}) *}" ) + compadd "$expl[@]" -QS '' -M 'r:|[_-]=* r:|=*' -ld tmp - \ + "${(@k)dopts}" && ret=0 fi - fi - if [[ -z "$tmp" ]]; then + if (( ${(@k)#odopts[(I)*=]} )); then + tmp=( "${(@M)descr:#(${(kj:|:)~odopts[(I)*=]}) *}" ) + compadd "$expl[@]" -QqS= -M 'r:|[_-]=* r:|=*' -ld tmp - \ + "${(@k)odopts[(I)*=]%=}" && ret=0 + fi + else compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' - \ "${(@k)opts}" "${(@k)odopts[(I)*[^=]]}" && ret=0 compadd "$expl[@]" -QqS= -M 'r:|[_-]=* r:|=*' - \ diff --git a/Completion/Base/_values b/Completion/Base/_values index 9be2d97f3..21f6908cc 100644 --- a/Completion/Base/_values +++ b/Completion/Base/_values @@ -285,29 +285,25 @@ else [[ -n "$sep" && ${#snames}+${#names}+${#onames} -ne 1 ]] && expl=( "-qS$sep" "$expl[@]" ) - tmp='' if [[ -n "$compconfig[describe_values]" && - "$compconfig[describe_values]" != *\!${words[1]}* ]]; then - if _display tmp odescr -M 'r:|[_-]=* r:|=*'; then - if (( $#snames )); then - compadd "$expl[@]" -y tmp -M 'r:|[_-]=* r:|=*' - \ - "$snames[@]" && ret=0 - compadd -n -S= -J "_$gdescr" -M 'r:|[_-]=* r:|=*' - \ - "${(@k)names}" && ret=0 - compadd -n -qS= -J "_$gdescr" -M 'r:|[_-]=* r:|=*' - \ - "${(@k)onames}" && ret=0 - elif (( $#names )); then - compadd -n -S= "$expl[@]" -y tmp -M 'r:|[_-]=* r:|=*' - \ - "${(@k)names}" && ret=0 - compadd -n -qS= -J "_$gdescr" -M 'r:|[_-]=* r:|=*' - \ - "${(@k)onames}" && ret=0 - else - compadd -n -qS= "$expl[@]" -y tmp -M 'r:|[_-]=* r:|=*' - \ - "${(@k)onames}" && ret=0 - fi + "$compconfig[describe_values]" != *\!${words[1]}* ]] && + _display descr "$odescr[@]"; then + if (( $#snames )); then + tmp=( "${(@M)descr:#(${(j:|:)~snames}) *}" ) + compadd "$expl[@]" -ld tmp -M 'r:|[_-]=* r:|=*' - \ + "${(@)tmp%% *}" && ret=0 fi - fi - if [[ -z "$tmp" ]]; then + if (( $#names )); then + tmp=( "${(@M)descr:#(${(kj:|:)~names}) *}" ) + compadd -S= "$expl[@]" -ld tmp -M 'r:|[_-]=* r:|=*' - \ + "${(@)tmp%% *}" && ret=0 + fi + if (( $#onames )); then + tmp=( "${(@M)descr:#(${(kj:|:)~onames}) *}" ) + compadd -qS= "$expl[@]" -ld tmp -M 'r:|[_-]=* r:|=*' - \ + "${(@)tmp%% *}" && ret=0 + fi + else compadd "$expl[@]" -M 'r:|[_-]=* r:|=*' - "$snames[@]" && ret=0 compadd -S= "$expl[@]" -M 'r:|[_-]=* r:|=*' - "${(@k)names}" && ret=0 compadd -qS= "$expl[@]" -M 'r:|[_-]=* r:|=*' - "${(@k)onames}" && ret=0 @@ -356,11 +352,12 @@ else eval ws\=\( "${action[3,-3]}" \) - if _display tmp ws; then - compadd "$expl[@]" -y tmp - "${(@)ws%%:*}" + if [[ -n "$compconfig[describe_values]" && + "$compconfig[describe_values]" != *\!${cmd}* ]] && + _display tmp "$ws[@]"; then + compadd "$expl[@]" -M 'r:|[_-]=* r:|=*' -ld tmp - "${(@)ws%%:*}" else - _message "$descr" - return 1 + compadd "$expl[@]" - "${(@)ws%%:*}" fi elif [[ "$action" = \(*\) ]]; then diff --git a/Completion/Core/_display b/Completion/Core/_display index d23361653..7a1072d92 100644 --- a/Completion/Core/_display +++ b/Completion/Core/_display @@ -1,82 +1,38 @@ #autoload -# This builds a display-list for the `-y' option of `compadd' and -# `compgen' out of the arguments it gets. The first argument is -# taken as the name of a parameter and the string built is stored -# into it. -# The second argument is the name of an array whose elements each -# contains a string to complete, optionally followed by a colon -# and a description. The display list created will contain one -# line per string with the description after it, all nicely -# aligned. Strings without descriptions are put at the end in a -# column-oriented fashion. -# All arguments after the second one are given as arguments to -# `compadd'. -# This function will also do the matching required to find out -# which strings will be included in the list. All elements that -# don't match will be removed from the array. This means that the -# special parameters `PREFIX' and `SUFFIX' have to be set up -# correctly before this function is called. +# This builds a display-list for the `-ld' option of `compadd' +# out of the arguments it gets. The first argument is taken as +# the name of a parameter and the array built is stored into it. +# The other arguments are strings consisting of the match optionally +# followed by a colon and a description. The display list created +# will contain one element per match with the description after it, +# all nicely aligned. -local _param="$1" _arr _len _i _tmp _simple +local _param="$1" _len _i _tmp _hasd -# Remove all descriptions not matched by the string on the line. -if [[ "${2[1]}" = \( ]]; then - _arr=( ${(Qo)=2[2,-2]} ) -else - _arr=( "${(@Po)2}" ) -fi +shift -_arr=( "${(@)_arr:#}" ) -compadd -D _arr "${(@)argv[3,-1]}" - "${(@)_arr%%:*}" +# First get the length of the longest string (to be able to align them). -[[ "${2[1]}" != \( ]] && eval "${2}=( \"\$_arr[@]\" )" +_len=-1 +for _i; do + _tmp="${#_i%%:*}" + [[ "$_i" = *:?* && _tmp -gt _len ]] && _len="$_tmp" +done -if (( $#_arr )); then +# Now we build the list in `_tmp'. - # There are strings left, first get the length of the longest of - # them (to be able to align them) and collect all strings without - # descriptions. - - _simple=() - _len=-1 - for _i in "$_arr[@]"; do - _tmp="${#_i%%:*}" - if [[ "$_i" = *:?* ]]; then - [[ _tmp -gt _len ]] && _len="$_tmp" - else - _simple=( "$_simple[@]" "${_i%:}" ) - fi - done - - if [[ _len -lt 0 ]]; then - eval "${_param}=''" - return 1 +_tmp=() +for _i; do + if [[ "$_i" = *:?* ]]; then + _tmp=( "$_tmp[@]" "${(r:_len:: :)_i%%:*} -- ${_i#*:}" ) + _hasd=yes + else + _tmp=( "$_tmp[@]" "${_i%:}" ) fi +done - # Now we build the list in `_tmp', adding one line per string. - - _tmp='' - for _i in "$_arr[@]"; do - [[ "$_i" = *:?* ]] && _tmp="$_tmp -${(r:_len:: :)_i%%:*} -- ${_i#*:}" - done - - # If there were strings without descriptions, we just add them by - # calling `print -c'. - - (( $#_simple )) && _tmp="${_tmp} -$(print -c - $_simple)" - - eval "${_param}=\"\${_tmp[2,-1]}\"" - - return 0 -else - - # None of the strings matches what's on the line, signal this by - # setting the parameter to an empty string and by the return value. +eval "${_param}=( \"\$_tmp[@]\" )" - eval "${_param}=''" - return 1 -fi +[[ -n "$_hasd" ]] diff --git a/Completion/User/_mount b/Completion/User/_mount index e92f56339..40bc3b4ea 100644 --- a/Completion/User/_mount +++ b/Completion/User/_mount @@ -191,7 +191,7 @@ if [[ "$words[1]" = mount ]]; then '-u[remount file system]' \ ':dev or dir:->devordir' \ ':mount point:_files -/' - + ) fss=( advfs ufs nfs mfs cdfs ) ;; *) @@ -204,7 +204,9 @@ if [[ "$words[1]" = mount ]]; then '-f[fake mount]' \ ':dev or dir:->devordir' \ ':mount point:_files -/' + ) fss=( ufs ) + ;; esac _arguments "$args[@]" && ret=0 @@ -228,7 +230,7 @@ case "$state" in fstype) compset -P '*,' _description expl 'file system type' - compadd "$expl[@]" -qS, -M 'L:no=' - "$fss[@]" && ret=0 + compadd "$expl[@]" -qS, -M 'L:|no=' - "$fss[@]" && ret=0 ;; fsopt) eval 'tmp=(' '"$_fs_'${(s:,:)^${options[-t]:-${deffs}}}'[@]"' ')' -- cgit 1.4.1