#autoload # 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" _len _i _tmp _hasd shift # First get the length of the longest string (to be able to align them). _len=-1 for _i; do _tmp="${#_i%%:*}" [[ "$_i" = *:?* && _tmp -gt _len ]] && _len="$_tmp" done # Now we build the list in `_tmp'. _tmp=() for _i; do if [[ "$_i" = *:?* ]]; then _tmp=( "$_tmp[@]" "${(r:_len:: :)_i%%:*} -- ${_i#*:}" ) _hasd=yes else _tmp=( "$_tmp[@]" "${_i%:}" ) fi done eval "${_param}=( \"\$_tmp[@]\" )" [[ -n "$_hasd" ]]