# Bash completion for t2locate

_t2locate() {
    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=(
        -f --file
        -o --output
        -d --database
        -s --separator
        -i --input-separator
        -h --help
    )

    case "$prev" in
        -f|--file|-o|--output)
            if type -t _filedir &> /dev/null; then
                _filedir
            else
                compopt -o filenames 2> /dev/null
                COMPREPLY=($(compgen -f -- "$cur"))
            fi
            return
            ;;
        -d|--database)
            if type -t _filedir &> /dev/null; then
                _filedir -d
            else
                compopt -o dirnames 2> /dev/null
                COMPREPLY=($(compgen -d -- "$cur"))
            fi
            return
            ;;
        -s|--separator|-i|--input-separator)
            return
            ;;
    esac

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

complete -F _t2locate t2locate
