# Bash completion for t2voipconv

_t2voipconv() {
    local cur prev word 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

    case "$prev" in
        -m|--mono-dir|-s|--stereo-dir|-o|--output-dir)
            if type -t _filedir &> /dev/null; then
                _filedir -d
            else
                compopt -o dirnames 2> /dev/null
                COMPREPLY=($(compgen -d -- "$cur"))
            fi
            return
            ;;
        -f|--format)
            COMPREPLY=($(compgen -W "amr amrnb amrwb g711a g711u g722 g723_1 g726 g726le g729 gsm" -- "$cur"))
            return
            ;;
    esac

    local args=(
        -m --mono-dir
        -s --stereo-dir
        -o --output-dir
        -S --no-stereo
        -i -interactive
        -y --yes
        -v --verbose
        -f --format
        --sox
        -h --help
    )

    if [[ "$cur" == -* ]]; then
        COMPREPLY=($(compgen -W "${args[*]}" -- "$cur"))
    elif type -t _filedir &> /dev/null; then
        _filedir
    else
        compopt -o filenames 2> /dev/null
        COMPREPLY=($(compgen -f -- "$cur"))
    fi
}

complete -F _t2voipconv t2voipconv
