_aria2c()
{
    local cur prev split=false
    COMPREPLY=()
    COMP_WORDBREAKS=${COMP_WORDBREAKS//=}

    cmd=${COMP_WORDS[0]}
    _get_comp_words_by_ref cur prev
    case $prev in
        --ftp-type)
            COMPREPLY=( $( compgen -W 'binary ascii' -- "$cur" ) )
            return 0
            ;;
        --proxy-method)
            COMPREPLY=( $( compgen -W 'get tunnel' -- "$cur" ) )
            return 0
            ;;
        --metalink-preferred-protocol)
            COMPREPLY=( $( compgen -W 'http https ftp none' -- "$cur" ) )
            return 0
            ;;
        --bt-min-crypto-level)
            COMPREPLY=( $( compgen -W 'plain arc4' -- "$cur" ) )
            return 0
            ;;
        --follow-metalink)
            COMPREPLY=( $( compgen -W 'true mem false' -- "$cur" ) )
            return 0
            ;;
        --file-allocation)
            COMPREPLY=( $( compgen -W 'none prealloc trunc falloc' -- "$cur" ) )
            return 0
            ;;
        --log-level)
            COMPREPLY=( $( compgen -W 'debug info notice warn error' -- "$cur" ) )
            return 0
            ;;
        --uri-selector)
            COMPREPLY=( $( compgen -W 'inorder feedback adaptive' -- "$cur" ) )
            return 0
            ;;
        --event-poll)
            COMPREPLY=( $( compgen -W 'epoll poll select' -- "$cur" ) )
            return 0
            ;;
        --follow-torrent)
            COMPREPLY=( $( compgen -W 'true mem false' -- "$cur" ) )
            return 0
            ;;
        --stream-piece-selector)
            COMPREPLY=( $( compgen -W 'default inorder random geom' -- "$cur" ) )
            return 0
            ;;
        --download-result)
            COMPREPLY=( $( compgen -W 'default full hide' -- "$cur" ) )
            return 0
            ;;
        --min-tls-version)
            COMPREPLY=( $( compgen -W 'TLSv1.1 TLSv1.2 TLSv1.3' -- "$cur" ) )
            return 0
            ;;
        --console-log-level)
            COMPREPLY=( $( compgen -W 'debug info notice warn error' -- "$cur" ) )
            return 0
            ;;
        --dir)
            _filedir -d
            return 0
            ;;
        --torrent-file)
            _filedir '@(torrent)'
            return 0
            ;;
        --metalink-file)
            _filedir '@(meta4|metalink)'
            return 0
            ;;
    esac
    case $cur in
        -*)
            COMPREPLY=( $( compgen -W '--version --help --help=#basic --help=#advanced --help=#http --help=#https --help=#ftp --help=#metalink --help=#bittorrent --help=#cookie --help=#hook --help=#file --help=#rpc --help=#checksum --help=#experimental --help=#deprecated --help=#help --help=#all --timeout --connect-timeout --max-tries --auto-save-interval --log --dir --out --split --daemon --daemon=false --referer --lowest-speed-limit --piece-length --max-overall-download-limit --max-download-limit --file-allocation --no-file-allocation-limit --allow-overwrite --allow-overwrite=false --realtime-chunk-checksum --realtime-chunk-checksum=false --check-integrity --check-integrity=false --netrc-path --continue --continue=false --no-netrc --no-netrc=false --input-file --deferred-input --deferred-input=false --max-concurrent-downloads --optimize-concurrent-downloads --optimize-concurrent-downloads=true --optimize-concurrent-downloads=false --optimize-concurrent-downloads=A:B --force-sequential --force-sequential=false --auto-file-renaming --auto-file-renaming=false --parameterized-uri --parameterized-uri=false --allow-piece-length-change --allow-piece-length-change=false --no-conf --no-conf=false --conf-path --stop --quiet --quiet=false --async-dns --async-dns=false --summary-interval --log-level --console-log-level --uri-selector --server-stat-timeout --server-stat-if --server-stat-of --remote-time --remote-time=false --max-file-not-found --event-poll --enable-rpc --enable-rpc=false --rpc-listen-port --rpc-user --rpc-passwd --rpc-max-request-size --rpc-listen-all --rpc-listen-all=false --rpc-allow-origin-all --rpc-allow-origin-all=false --rpc-certificate --rpc-private-key --rpc-secure --rpc-secure=false --rpc-save-upload-metadata --rpc-save-upload-metadata=false --dry-run --dry-run=false --reuse-uri --reuse-uri=false --on-download-start --on-download-pause --on-download-stop --on-download-complete --on-download-error --interface --multiple-interface --disable-ipv6 --disable-ipv6=false --human-readable --human-readable=false --remove-control-file --remove-control-file=false --always-resume --always-resume=false --max-resume-failure-tries --save-session --max-connection-per-server --min-split-size --conditional-get --conditional-get=false --enable-async-dns6 --enable-async-dns6=false --max-download-result --retry-wait --async-dns-server --show-console-readout --show-console-readout=false --stream-piece-selector --truncate-console-readout --truncate-console-readout=false --pause --pause=false --download-result --hash-check-only --hash-check-only=false --checksum --stop-with-process --enable-mmap --enable-mmap=false --force-save --force-save=false --save-not-found --save-not-found=false --disk-cache --gid --save-session-interval --enable-color --enable-color=false --rpc-secret --dscp --pause-metadata --pause-metadata=false --rlimit-nofile --min-tls-version --socket-recv-buffer-size --max-mmap-limit --stderr --stderr=false --keep-unfinished-download-result --keep-unfinished-download-result=false --ftp-user --ftp-passwd --ftp-type --ftp-pasv --ftp-pasv=false --ftp-reuse-connection --ftp-reuse-connection=false --ssh-host-key-md --http-user --http-passwd --user-agent --load-cookies --save-cookies --enable-http-keep-alive --enable-http-keep-alive=false --enable-http-pipelining --enable-http-pipelining=false --header --certificate --private-key --ca-certificate --check-certificate --check-certificate=false --use-head --use-head=false --http-auth-challenge --http-auth-challenge=false --http-no-cache --http-no-cache=false --http-accept-gzip --http-accept-gzip=false --content-disposition-default-utf8 --content-disposition-default-utf8=false --no-want-digest-header --no-want-digest-header=false --http-proxy --https-proxy --ftp-proxy --all-proxy --no-proxy --proxy-method --http-proxy-user --http-proxy-passwd --https-proxy-user --https-proxy-passwd --ftp-proxy-user --ftp-proxy-passwd --all-proxy-user --all-proxy-passwd --show-files --show-files=false --max-overall-upload-limit --max-upload-limit --torrent-file --listen-port --follow-torrent --select-file --seed-time --seed-ratio --peer-id-prefix --peer-agent --enable-peer-exchange --enable-peer-exchange=false --enable-dht --enable-dht=false --dht-listen-port --dht-entry-point --dht-file-path --enable-dht6 --enable-dht6=false --dht-listen-addr6 --dht-entry-point6 --dht-file-path6 --bt-min-crypto-level --bt-require-crypto --bt-require-crypto=false --bt-request-peer-speed-limit --bt-max-open-files --bt-seed-unverified --bt-seed-unverified=false --bt-hash-check-seed --bt-hash-check-seed=false --bt-max-peers --bt-external-ip --index-out --bt-tracker-interval --bt-stop-timeout --bt-prioritize-piece --bt-save-metadata --bt-save-metadata=false --bt-metadata-only --bt-metadata-only=false --bt-enable-lpd --bt-enable-lpd=false --bt-lpd-interface --bt-tracker-timeout --bt-tracker-connect-timeout --dht-message-timeout --on-bt-download-complete --bt-tracker --bt-exclude-tracker --bt-remove-unselected-file --bt-remove-unselected-file=false --bt-detach-seed-only --bt-detach-seed-only=false --bt-force-encryption --bt-force-encryption=false --bt-enable-hook-after-hash-check --bt-enable-hook-after-hash-check=false --bt-load-saved-metadata --bt-load-saved-metadata=false --metalink-file --metalink-version --metalink-language --metalink-os --metalink-location --follow-metalink --metalink-preferred-protocol --metalink-enable-unique-protocol --metalink-enable-unique-protocol=false --metalink-base-uri ' -- "$cur" ) )
            ;;
        *)
            _filedir '@(torrent|meta4|metalink|text|txt|list|lst)'
            [ ${#COMPREPLY[@]} -eq 0 ] && _filedir
            return 0
    esac
    return 0
}
complete -F _aria2c aria2c
