_hummingbird_completion()
{
    local compopt current prev optlist

    current="${COMP_WORDS[$COMP_CWORD]}"
    
    prev="${COMP_WORDS[$COMP_CWORD - 1]}"

    compopt=""

    optlist="--allowuaf -6  \
             --alt-proxy -A \
             --auth-retry -Y \
             --auto-sess -a \
             --cache-password -H \
             --cipher -C \
             --compress -c \
             --dc -D \
             --def-keydir -k \
             --epki-ca \
             --epki-cert \
             --epki-key \
             --eval -e \
             --gremlin -G \
             --gui-version -E \
             --help -h \
             --ignore-dns-push -i \
             --list-data-ciphers \
             --mtu \
             --network-lock -N \
             --allow-private-network \
             --allow-ping \
             --allow-ipv6ndp \
             --no-cert -x \
             --password -p \
             --peer-info -I \
             --persist-tun -j \
             --pk-password -z \
             --port -R \
             --proto -P \
             --proxy-basic -b \
             --proxy-host -y \
             --proxy-password -W \
             --proxy-port -q \
             --proxy-username -U \
             --recover-network \
             --remove-wireguard-device \
             --response -r \
             --server -s \
             --ssl-debug \
             --tcp-queue-limit -l \
             --tcprof-override -X \
             --timeout -t \
             --tvm-override -M \
             --username -u \
             --version -v"

    if [[ "${current}" =~ ^- ]]; then
        compopt=$optlist
    else
        case "${prev}" in
            --allowuaf|-6)
                compopt="yes no default"
                ;;

            --alt-proxy|-A)
                compopt=""
                ;;

            --auth-retry|-Y)
                compopt=""
                ;;

            --auto-sess|-a)
                compopt=""
                ;;

            --cache-password|-H)
                compopt=""
                ;;

            --cipher|-C)
                compopt="AES-128-GCM AES-192-GCM AES-256-GCM CHACHA20-POLY1305"
                ;;

            --compress|-c)
                compopt="yes no asym"
                ;;

            --dc|-D)
                compopt="cookie"
                ;;

            --def-keydir|-k)
                compopt="bi 0 1"
                ;;

            --epki-ca)
                compopt="ca"
                ;;

            --epki-cert)
                compopt="cert"
                ;;

            --epki-key)
                compopt="key"
                ;;

            --eval|-e)
                compopt=""
                ;;

            --gremlin|-g)
                compopt="send_delay_ms recv_delay_ms send_drop_prob recv_drop_prob"
                ;;

            --gui-version|-E)
                compopt="text"
                ;;

            --help|-h)
                compopt=""
                ;;

            --ignore-dns-push|-i)
                compopt=""
                ;;

            --list-data-ciphers|-D)
                compopt=""
                ;;

            --mtu)
                compopt="mtu_value"
                ;;

            --allow-private-network)
                compopt="on off"
                ;;

            --network-lock|-N)
                compopt="on iptables nftables pf off"
                ;;

            --allow-ping)
                compopt="on off input output"
                ;;

            --allow-ipv6ndp)
                compopt="on off"
                ;;

            --no-cert|-x)
                compopt=""
                ;;

            --password|-p)
                compopt="password"
                ;;

            --peer-info|-e)
                compopt=""
                ;;

            --persist-tun|-j)
                compopt=""
                ;;

            --pk-password|-z)
                compopt="password"
                ;;

            --port|-R)
                compopt="port_number"
                ;;

            --proto|-P)
                compopt="tcp udp"
                ;;

            --proxy-basic|-b)
                compopt=""
                ;;

            --proxy-host|-y)
                compopt="hostname ip_address"
                ;;

            --proxy-password|-W)
                compopt="password"
                ;;

            --proxy-port|-q)
                compopt="port_number"
                ;;

            --proxy-username|-U)
                compopt="username"
                ;;

            --recover-network)
                compopt=""
                ;;

            --remove-wireguard-device)
                compopt=""
                ;;

            --response|-r)
                compopt="response"
                ;;

            --server|-s)
                compopt="server_host server_ip"
                ;;

            --ssl-debug)
                compopt="value"
                ;;

            --tcp-queue-limit|-l)
                compopt="value"
                ;;

            --tcprof-override|-X)
                compopt="legacy preferred ..."
                ;;

            --timeout|-t)
                compopt="seconds"
                ;;

            --tvm-override|-M)
                compopt="disabled default tls_1_x"
                ;;

            --username|-u)
                compopt="username"
                ;;

            --version|-v)
                compopt=""
                ;;

            *)
                compopt=$(compgen -f)
                ;;
        esac
    fi

    if [ "${compopt}" == "" ]; then
        compopt=$(compgen -f)
    fi

    COMPREPLY=($(compgen -W "${compopt}" -- ${current}))

    return 0
}

complete -F _hummingbird_completion hummingbird
