# Debian smali completion                             -*- shell-script -*-

_smali()
{
    local cur prev words cword
    _init_completion || return

    local GENERIC_OPTIONS='
        -a --api
        --allow-odex-opcodes
        -h --help
        -j --jobs
        -o --output
        -v --version
    '

    # see if the user selected a command already
    local COMMANDS=(
        "assemble"
        "help"
    )

    local command i
    for (( i=0; i < ${#words[@]}-1; i++ )); do
        if [[ ${COMMANDS[@]} =~ ${words[i]} ]]; then
            command=${words[i]}
            break
        fi
    done

    # Complete a --option<SPACE><TAB>
    case $prev in
        -o|--output)
            _filedir
            return 0
            ;;
    esac

    # supported options per command
    if [[ "$cur" == -* ]]; then
        case $command in
            assemble|ass|as|a)
                COMPREPLY=( $( compgen -W "$GENERIC_OPTIONS" -- "$cur" ) )
                return 0
                ;;
            help)
                return 0
                ;;
        esac
    fi

    # specific command arguments
    if [[ -n $command ]]; then
        case $command in
            assemble|ass|as|a)
                _filedir 'smali'
                return 0
                ;;
        esac
    fi

    # no command yet, show what commands we have
    if [ "$command" = "" ]; then
        COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) )
    fi

    return 0
} &&
complete -F _smali smali

# ex: ts=4 sw=4 et filetype=sh
