---
source: lib/src/complete/zsh.rs
expression: "complete_zsh_init(\"usage\")"
---
# @generated by usage-cli — auto-completion for usage shebang scripts
# Source this file from your zshrc to enable <Tab> completion for any command
# on $PATH whose first line is a `usage` shebang.

_usage_default_complete() {
    emulate -L zsh
    setopt localoptions nonomatch extendedglob
    local cmd cmdpath
    cmd="${words[1]}"
    if [[ "$cmd" == */* ]]; then
        cmdpath="$cmd"
    elif (( ${+commands[$cmd]} )); then
        cmdpath="${commands[$cmd]}"
    fi

    if [[ -n "$cmdpath" && -f "$cmdpath" ]]; then
        local first
        if IFS= read -r first < "$cmdpath" 2>/dev/null && [[ "$first" == "#!"*"usage"* ]]; then
            if (( ${+commands[usage]} )); then
                local -a values=() descs=() inserts=()
                local needs_menu=0 line
                while IFS= read -r line; do
                  local -a parts=("${(@ps:\t:)line}")
                  values+=("${parts[1]}")
                  descs+=("${parts[2]}")
                  inserts+=("${parts[3]}")
                  [[ "${parts[3]}" == "'"* ]] && needs_menu=1
                done < <(command usage complete-word --shell zsh -f "$cmdpath" --cword=$((CURRENT - 1)) -- "${(Q)words[@]}")
                (( needs_menu )) && compstate[insert]=menu
                if (( ${#inserts[@]} )); then
                  local -a _usage_display=()
                  local _usage_i _usage_max=0 _usage_v _usage_pad
                  for _usage_v in "${values[@]}"; do
                    (( ${#_usage_v} > _usage_max )) && _usage_max=${#_usage_v}
                  done
                  for ((_usage_i=1; _usage_i<=${#values[@]}; _usage_i++)); do
                    if [[ -n "${descs[_usage_i]}" ]]; then
                      _usage_pad=$(( _usage_max - ${#values[_usage_i]} ))
                      _usage_display+=("${values[_usage_i]}${(l:_usage_pad:: :)}  -- ${descs[_usage_i]}")
                    else
                      _usage_display+=("${values[_usage_i]}")
                    fi
                  done
                  compadd -l -d _usage_display -U -Q -S '' -a inserts
                fi
                return $?
            fi
        fi
    fi

    # Not a usage shebang script — fall back to file completion
    _files
}

compdef _usage_default_complete -default-
# vim: noet ci pi sts=0 sw=4 ts=4
