_av1an() {
    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="av1an"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        av1an)
            opts="-i -o -q -l -r -k -y -n -w -s -x -e -v -p -f -a -m -c -h -V --proxy --temp --quiet --verbose --log-file --log-level --completions --resume --keep --force --no-defaults --max-tries --workers --set-thread-affinity --scaler --vspipe-args --scenes --sc-only --split-method --sc-method --sc-downscale-height --sc-pix-format --extra-split --extra-split-sec --min-scene-len --force-keyframes --encoder --video-params --passes --tile-auto --ffmpeg --audio-params --ignore-frame-mismatch --chunk-method --chunk-order --photon-noise --chroma-noise --photon-noise-width --photon-noise-height --concat --pix-format --zones --cache-mode --vmaf --vmaf-path --vmaf-res --probe-res --vmaf-threads --vmaf-filter --target-quality --qp-range --interp-method --target-metric --probes --probing-rate --probe-video-params --probing-vmaf-features --probing-stat --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                -i)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --proxy)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -o)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --temp)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --log-file)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -l)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --log-level)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --completions)
                    COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
                    return 0
                    ;;
                --max-tries)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --workers)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -w)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --set-thread-affinity)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --scaler)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --vspipe-args)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --scenes)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -s)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --split-method)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --sc-method)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --sc-downscale-height)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --sc-pix-format)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --extra-split)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -x)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --extra-split-sec)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --min-scene-len)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --force-keyframes)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --encoder)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -e)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --video-params)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -v)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --passes)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -p)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --ffmpeg)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -f)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --audio-params)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -a)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --chunk-method)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -m)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --chunk-order)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --photon-noise)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --photon-noise-width)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --photon-noise-height)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --concat)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -c)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --pix-format)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --zones)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --cache-mode)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --vmaf-path)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --vmaf-res)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --probe-res)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --vmaf-threads)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --vmaf-filter)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --target-quality)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --qp-range)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --interp-method)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --target-metric)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --probes)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --probing-rate)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --probe-video-params)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --probing-vmaf-features)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --probing-stat)
                    COMPREPLY=($(compgen -f "${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 _av1an -o nosort -o bashdefault -o default av1an
else
    complete -F _av1an -o bashdefault -o default av1an
fi
