_zizmor() {
    local i cur prev opts cmd
    COMPREPLY=()
    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
        cur="$2"
    else
        cur="${COMP_WORDS[COMP_CWORD]}"
    fi
    prev="$3"
    cmd=""
    opts=""

    for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="zizmor"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        zizmor)
            opts="-p -v -q -o -c -h -V --collect --strict-collection --fix --pedantic --persona --min-severity --min-confidence --no-ignores --verbose --quiet --format --no-progress --color --render-links --show-audit-urls --no-exit-codes --naches --offline --gh-token --github-token --zizmor-github-token --gh-hostname --no-online-audits --cache-dir --lsp --stdio --config --no-config --completions --thanks --help --version <INPUT>..."
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --collect)
                    COMPREPLY=($(compgen -W "all default workflows actions dependabot" -- "${cur}"))
                    return 0
                    ;;
                --fix)
                    COMPREPLY=($(compgen -W "safe unsafe-only all" -- "${cur}"))
                    return 0
                    ;;
                --persona)
                    COMPREPLY=($(compgen -W "auditor pedantic regular" -- "${cur}"))
                    return 0
                    ;;
                --min-severity)
                    COMPREPLY=($(compgen -W "informational low medium high" -- "${cur}"))
                    return 0
                    ;;
                --min-confidence)
                    COMPREPLY=($(compgen -W "low medium high" -- "${cur}"))
                    return 0
                    ;;
                --format)
                    COMPREPLY=($(compgen -W "plain json json-v1 sarif github" -- "${cur}"))
                    return 0
                    ;;
                --color)
                    COMPREPLY=($(compgen -W "auto always never" -- "${cur}"))
                    return 0
                    ;;
                --render-links)
                    COMPREPLY=($(compgen -W "auto always never" -- "${cur}"))
                    return 0
                    ;;
                --show-audit-urls)
                    COMPREPLY=($(compgen -W "auto always never" -- "${cur}"))
                    return 0
                    ;;
                --gh-token)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --github-token)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --zizmor-github-token)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --gh-hostname)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --cache-dir)
                    COMPREPLY=()
                    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
                        compopt -o plusdirs
                    fi
                    return 0
                    ;;
                --config)
                    local oldifs
                    if [ -n "${IFS+x}" ]; then
                        oldifs="$IFS"
                    fi
                    IFS=$'\n'
                    COMPREPLY=($(compgen -f "${cur}"))
                    if [ -n "${oldifs+x}" ]; then
                        IFS="$oldifs"
                    fi
                    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
                        compopt -o filenames
                    fi
                    return 0
                    ;;
                -c)
                    local oldifs
                    if [ -n "${IFS+x}" ]; then
                        oldifs="$IFS"
                    fi
                    IFS=$'\n'
                    COMPREPLY=($(compgen -f "${cur}"))
                    if [ -n "${oldifs+x}" ]; then
                        IFS="$oldifs"
                    fi
                    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
                        compopt -o filenames
                    fi
                    return 0
                    ;;
                --completions)
                    COMPREPLY=($(compgen -W "bash elvish fish nushell powershell zsh" -- "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    complete -F _zizmor -o nosort -o bashdefault -o default zizmor
else
    complete -F _zizmor -o bashdefault -o default zizmor
fi
