#compdef mise
# @generated by usage-argv for `mise __complete_word__ --shell zsh`

_mise() {
    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 'mise' __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)
            local __usage_glob="*.(${(j:|:)extensions})"
            _files -g "$__usage_glob" && __usage_ret=0
            ;;
    esac
    return $__usage_ret
}
# Installed either way. Dropped in `$fpath` as `_mise`, compinit autoloads the file and calls
# the function named after it — which is why the function is `_mise` and not something tidier.
# Sourced from a config instead, nothing has called it yet, so it registers itself.
if [ "$funcstack[1]" = "_mise" ]; then
    _mise "$@"
else
    compdef _mise 'mise'
fi
