1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-20 16:01:04 +02:00
zsh/Completion/Core/_display
1999-09-14 14:55:37 +00:00

38 lines
912 B
Text

#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" ]]