# Bash completion for t2whois

_t2whois() {
    local cur prev words cword

    if type -t _init_completion &> /dev/null; then
        _init_completion -n = || return
    else
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
    fi

    local args=(
        "-r" "-R" "-D" "-a" "-p"
        "-d" "-e" "-o" "-q" "-k"
        "-l" "-H" "-t" "-s" "-L"
        "-V" "-h"
    )

    case "$prev" in
        -r|-d|-e|-k)
            if type -t _filedir &> /dev/null; then
                _filedir
            else
                compopt -o filenames 2> /dev/null
                COMPREPLY=($(compgen -f -- "$cur"))
            fi
            return
            ;;
        -s|-t)
            return
            ;;
        -o)
            args=(
                ip netmask net mask range
                org country county city asn
                lat lng prec netid
            )
    esac

    COMPREPLY=($(compgen -W "${args[*]}" -- "$cur"))
}

complete -F _t2whois t2whois
