# bash completion for bluez utils -*- shell-script -*- proc _bluetooth_adresses { if [[ -n ${COMP_BLUETOOTH_SCAN:-} ]] { setvar COMPREPLY = ''( $( compgen -W "$( hcitool scan | \ awk '/^\t/{print $1}' )" -- "$cur" ) ) } } proc _bluetooth_devices { setvar COMPREPLY = ''( $( compgen -W "$( hcitool dev | \ awk '/^\t/{print $1}' )" -- "$cur" ) ) } proc _bluetooth_services { setvar COMPREPLY = ''( $( compgen -W 'DID SP DUN LAN FAX OPUSH FTP HS HF HFAG SAP NAP GN PANU HCRP HID CIP A2SRC A2SNK AVRCT AVRTG UDIUE UDITE SYNCML' \ -- "$cur" ) ) } proc _bluetooth_packet_types { setvar COMPREPLY = ''( $( compgen -W 'DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3' \ -- "$cur" ) ) } proc _hcitool { local cur prev words cword split _init_completion -s || return case (prev) { -i { _bluetooth_devices return 0 } --role { setvar COMPREPLY = ''( $( compgen -W 'm s' -- "$cur" ) ) return 0 } --pkt-type { _bluetooth_packet_types return 0 } } $split && return 0 local arg _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W 'dev inq scan name info spinq epinq cmd con cc dc sr cpt rssi lq tpl afh lst auth enc key clkoff clock' -- "$cur" ) ) } } else { local args case (arg) { name|info|dc|rssi|lq|afh|auth|key|clkoff|lst { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } } cc { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--role --pkt-type' -- "$cur" ) ) } else { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } } } sr { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } else { setvar COMPREPLY = ''( $( compgen -W 'master slave' -- "$cur" ) ) } } cpt { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } else { _bluetooth_packet_types } } tpl|enc|clock { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } else { setvar COMPREPLY = ''( $( compgen -W '0 1' -- "$cur" ) ) } } } } } && complete -F _hcitool hcitool proc _sdptool { local cur prev words cword split _init_completion -s || return case (prev) { --bdaddr { _bluetooth_adresses return 0 } } $split && return 0 local arg _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W 'search browse records add del get setattr setseq' -- "$cur" ) ) } } else { case (arg) { search { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--bdaddr --tree --raw --xml' \ -- "$cur" ) ) } else { _bluetooth_services } } browse|records { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--tree --raw --xml' -- "$cur" ) ) } else { _bluetooth_adresses } } add { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--handle --channel' -- "$cur" ) ) } else { _bluetooth_services } } get { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--bdaddr --tree --raw --xml' \ -- "$cur" ) ) } } } } } && complete -F _sdptool sdptool proc _l2ping { local cur prev words cword _init_completion || return case (prev) { -i { _bluetooth_devices return 0 } -s|-c|-t|-d { return 0 } } if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '$( _parse_usage "$1" )' -- "$cur" ) ) } else { _bluetooth_adresses } } && complete -F _l2ping l2ping proc _rfcomm { local cur prev words cword _init_completion || return case (prev) { -f|--config { _filedir return 0 } -i { _bluetooth_devices _bluetooth_adresses return 0 } } local arg _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W 'show connect listen watch bind release' -- "$cur" ) ) } } else { local args _count_args if [[ $args -eq 2 ]] { _bluetooth_devices } else { case (arg) { connect|bind { if [[ $args -eq 3 ]] { _bluetooth_adresses } } } } } } && complete -F _rfcomm rfcomm proc _ciptool { local cur prev words cword _init_completion || return case (prev) { -i { _bluetooth_devices _bluetooth_adresses return 0 } } local arg _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W 'show search connect release loopback' \ -- "$cur" ) ) } } else { local args case (arg) { connect|release|loopback { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } } } } } && complete -F _ciptool ciptool proc _dfutool { local cur prev words cword _init_completion || return case (prev) { -d|--device { _bluetooth_devices return 0 } } if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { local args _count_args case (args) { 1 { setvar COMPREPLY = ''( $( compgen -W 'verify modify upgrade archive' \ -- "$cur" ) ) } 2 { _filedir } } } } && complete -F _dfutool dfutool proc _hciconfig { local cur prev words cword _init_completion || return local arg _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--help --all' -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W 'up down reset rstat auth noauth encrypt noencrypt secmgr nosecmgr piscan noscan iscan pscan ptype name class voice iac inqmode inqdata inqtype inqparams pageparms pageto afhmode aclmtu scomtu putkey delkey commands features version revision lm' -- "$cur" ) ) } } else { local args case (arg) { putkey|delkey { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } } lm { _count_args if [[ $args -eq 2 ]] { setvar COMPREPLY = ''( $( compgen -W 'MASTER SLAVE NONE ACCEPT' \ -- "$cur" ) ) } } ptype { _count_args if [[ $args -eq 2 ]] { _bluetooth_packet_types } } } } } && complete -F _hciconfig hciconfig proc _hciattach { local cur prev words cword _init_completion || return if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '-n -p -t -b -s -l' -- "$cur" ) ) } else { local args _count_args case (args) { 1 { setvar COMPREPLY = ''( $( printf '%s\n' /dev/tty* ) ) setvar COMPREPLY = ''( $( compgen -W '${COMPREPLY[@]} ${COMPREPLY[@]#/dev/}' -- "$cur" ) ) } 2 { setvar COMPREPLY = ''( $( compgen -W 'any ericsson digi xircom csr bboxes swave bcsp 0x0105 0x080a 0x0160 0x0002' -- "$cur" ) ) } 3 { setvar COMPREPLY = ''( $( compgen -W '9600 19200 38400 57600 115200 230400 460800 921600' -- "$cur" ) ) } 4 { setvar COMPREPLY = ''( $( compgen -W 'flow noflow' -- "$cur" ) ) } 5 { _bluetooth_adresses } } } } && complete -F _hciattach hciattach # ex: ts=4 sw=4 et filetype=sh