#compdef usage
# @generated by usage-argv for `usage __complete_word__ --shell zsh`
_usage() {
local -a values=() descriptions=() inserts=() extensions=()
local -a __usage_words=()
local __usage_files= __usage_line __usage_menu=0 __usage_input __usage_prefix
local __usage_unprefixed __usage_command __usage_word
local __usage_assignment='^[A-Za-z_][A-Za-z0-9_]*\+?='
local -A __usage_aliases_seen=()
# `$BUFFER[1,CURSOR]` is the text before the cursor, cut with zsh's own offset — see the
# bash script on why the cutting happens here rather than through a `--cursor` argument.
__usage_input="${BUFFER[1,CURSOR]}"
while (( 1 )); do
__usage_prefix="${__usage_input%%[^[:blank:]]*}"
__usage_unprefixed="${__usage_input#"$__usage_prefix"}"
__usage_words=("${(z)__usage_unprefixed}")
__usage_command=
for __usage_word in "${__usage_words[@]}"; do
if [[ "$__usage_word" =~ $__usage_assignment ]]; then
__usage_unprefixed="${__usage_unprefixed#"$__usage_word"}"
__usage_prefix+="$__usage_word${__usage_unprefixed%%[^[:blank:]]*}"
__usage_unprefixed="${__usage_unprefixed#"${__usage_unprefixed%%[^[:blank:]]*}"}"
else
__usage_command="$__usage_word"
break
fi
done
[[ "${+aliases[$__usage_command]}" == 1 &&
-z "${__usage_aliases_seen[$__usage_command]-}" ]] || break
__usage_aliases_seen[$__usage_command]=1
__usage_input="${__usage_prefix}${aliases[$__usage_command]}${__usage_unprefixed#"$__usage_command"}"
done
while IFS= read -r __usage_line; do
case "$__usage_line" in
$'\001files') __usage_files=any; continue ;;
$'\001dirs') __usage_files=dirs; continue ;;
$'\001executables') __usage_files=executables; continue ;;
$'\001commands') __usage_files=commands; continue ;;
$'\001extensions\t'*)
__usage_files=extensions
extensions=("${(@ps:\t:)${__usage_line#*$'\t'}}")
continue
;;
'') continue ;;
esac
local -a parts=("${(@ps:\t:)__usage_line}")
values+=("${parts[1]}")
descriptions+=("${parts[2]}")
inserts+=("${parts[3]}")
# A quoted insert means the value needed quoting, and zsh should offer a menu rather
# than silently inserting one of several possibilities.
[[ "${parts[3]}" == "'"* ]] && __usage_menu=1
done < <(command 'usage' __complete_word__ --shell zsh \
--line "$__usage_input" 2>/dev/null)
local __usage_ret=1
(( __usage_menu )) && compstate[insert]=menu
if (( ${#inserts[@]} )); then
local -a display=()
local i max=0 value pad
for value in "${values[@]}"; do
(( ${#value} > max )) && max=${#value}
done
for (( i = 1; i <= ${#values[@]}; i++ )); do
if [[ -n "${descriptions[i]}" ]]; then
pad=$(( max - ${#values[i]} ))
display+=("${values[i]}${(l:pad:: :)} -- ${descriptions[i]}")
else
display+=("${values[i]}")
fi
done
# `-U` because the binary already filtered by the typed prefix, and `-Q` because the
# inserts are quoted already.
compadd -l -d display -U -Q -S '' -a inserts && __usage_ret=0
fi
case "$__usage_files" in
any) _files && __usage_ret=0 ;;
dirs) _files -/ && __usage_ret=0 ;;
executables) _files -g '*(-/,*)' && __usage_ret=0 ;;
commands) _command_names && __usage_ret=0 ;;
extensions)
# `_files -g` evaluates its argument as a glob, qualifiers and all, so the pattern is
# built only from names that cannot change its shape. Anything else on the line is
# dropped rather than quoted: `)(e:…:)` in an "extension" would otherwise run as
# code for every file the glob reached.
local __usage_extension
local -a __usage_safe=()
for __usage_extension in "${extensions[@]}"; do
[[ -n "$__usage_extension" && "$__usage_extension" != *[^[:alnum:]_.+-]* ]] &&
__usage_safe+=("$__usage_extension")
done
# One name is written bare: `*.(toml)` would read its group as glob qualifiers.
if (( ${#__usage_safe[@]} == 1 )); then
_files -g "*.${__usage_safe[1]}" && __usage_ret=0
elif (( ${#__usage_safe[@]} )); then
_files -g "*.(${(j:|:)__usage_safe})" && __usage_ret=0
else
_files && __usage_ret=0
fi
;;
esac
return $__usage_ret
}
# Installed either way. Dropped in `$fpath` as `_usage`, compinit autoloads the file and calls
# the function named after it — which is why the function is `_usage` and not something tidier.
# Sourced from a config instead, nothing has called it yet, so it registers itself.
if [ "$funcstack[1]" = "_usage" ]; then
_usage "$@"
else
compdef _usage 'usage'
fi