1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-19 21:44:11 +01:00
zsh/Completion/Commands/_complete_help

92 lines
2.5 KiB
Plaintext
Raw Normal View History

1999-11-15 13:01:47 +01:00
#compdef -k complete-word \C-xh
_complete_help() {
setopt localoptions nullglob rcexpandparam extendedglob
unsetopt markdirs globsubst shwordsplit nounset ksharrays
2000-04-01 22:43:43 +02:00
local _sort_tags=_help_sort_tags text i j k
typeset -A help_funcs help_tags help_sfuncs help_styles
1999-11-15 13:01:47 +01:00
compadd() { return 1 }
2000-04-01 22:43:43 +02:00
zstyle() {
local _f="${${(@)${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"
[[ -z "$_f" ]] && _f="${${(@)funcstack[2,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}"
if [[ "$help_sfuncs[$2]" != *${_f}* ||
"$help_styles[${2}${_f}]" != *${3}* ]]; then
[[ "$help_sfuncs[$2]" != *${_f}* ]] &&
help_sfuncs[$2]="${help_sfuncs[$2]}:${_f}"
local _t
case "$1" in
-s) _t='[string] ';;
-a) _t='[array] ';;
-h) _t='[assoc] ';;
*) _t='[boolean]';;
esac
help_styles[${2}${_f}]="${help_styles[${2}${_f}]},${_t} ${3}:${_f}"
fi
# No need to call the completers more than once with different match specs.
if [[ "$3" = matcher-list ]]; then
eval "${4}=( '' )"
else
builtin zstyle "$@"
fi
2000-04-01 22:43:43 +02:00
}
1999-11-15 13:01:47 +01:00
_main_complete
2000-04-01 22:43:43 +02:00
unfunction compadd zstyle
1999-11-15 13:01:47 +01:00
2000-04-01 22:43:43 +02:00
for i in "${(@ok)help_funcs}"; do
1999-11-15 13:01:47 +01:00
text="${text}
2000-04-01 22:43:43 +02:00
tags in context :completion:${i}:"
tmp=()
for j in "${(@s.:.)help_funcs[$i][2,-1]}"; do
tmp=( "$tmp[@]" "${(@s.,.)help_tags[${i}${j}][2,-1]}" )
done
zformat -a tmp ' (' "$tmp[@]"
tmp=( '
'${^tmp}')' )
text="${text}${tmp}"
1999-11-15 13:01:47 +01:00
done
2000-04-03 14:56:31 +02:00
if [[ ${NUMERIC:-1} -ne 1 ]]; then
text="$text
2000-04-01 22:43:43 +02:00
"
2000-04-03 14:56:31 +02:00
for i in "${(@ok)help_sfuncs}"; do
text="${text}
2000-04-01 22:43:43 +02:00
styles in context ${i}"
2000-04-03 14:56:31 +02:00
tmp=()
for j in "${(@s.:.)help_sfuncs[$i][2,-1]}"; do
tmp=( "$tmp[@]" "${(@s.,.)help_styles[${i}${j}][2,-1]}" )
done
zformat -a tmp ' (' "$tmp[@]"
tmp=( '
2000-04-01 22:43:43 +02:00
'${^tmp}')' )
2000-04-03 14:56:31 +02:00
text="${text}${tmp}"
done
fi
2000-04-01 22:43:43 +02:00
compstate[list]='list force'
1999-11-15 13:01:47 +01:00
compstate[insert]=''
compadd -UX "$text[2,-1]" -n ''
}
_help_sort_tags() {
2000-04-01 22:43:43 +02:00
local f="${${(@)${(@)funcstack[3,(i)_(main_complete|complete|approximate|normal)]}:#_(wanted|requested|loop|try)}% *}"
if [[ "$help_funcs[$curcontext]" != *${f}* ||
"$help_tags[${curcontext}${f}]" != *(${(j:|:)~argv})* ]]; then
[[ "$help_funcs[$curcontext]" != *${f}* ]] &&
help_funcs[$curcontext]="${help_funcs[$curcontext]}:${f}"
help_tags[${curcontext}${f}]="${help_tags[${curcontext}${f}]},${argv}:${f}"
comptry "$@"
fi
1999-11-15 13:01:47 +01:00
}
_complete_help "$@"