_tbtadm()
{
    local cur prev opts acl devices

    acl=/var/lib/thunderbolt/acl
    devices=/sys/bus/thunderbolt/devices

    COMPREPLY=()
    cur="$2"
    command="${COMP_WORDS[1]}"
    opts="devices peers topology approve approve-all acl add remove remove-all"

    case "$command" in
    approve|add|remove)
        local routestrings
        routestrings="$( [ -d ${devices} ] && command ls ${devices} | command grep -v domain | command grep -Fv . | command grep -v [0-9]-0)"
        COMPREPLY+=( $(compgen -W "${routestrings}" -- "$cur") )
        ;;&
    approve|approve-all)
        COMPREPLY+=( $(compgen -W "--once" -- "$cur") )
        ;;
    remove)
        local uuids
        uuids="$( [ -d ${acl} ] && command ls ${acl})"
        COMPREPLY+=( $(compgen -W "${uuids}" -- "$cur") )
        ;;
    *)
        if [[ ${COMP_CWORD} = 1 ]]; then
            COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
        fi
        ;;
    esac;

    return 0
}

complete -F _tbtadm tbtadm
