blob: 7a1072d92b9442e3a971b62d784e485470ddcf0f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#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" ]]
|