# bash completion for bluez utils -*- shell-script -*- proc _bluetooth_adresses { if [[ -n ${COMP_BLUETOOTH_SCAN:-} ]] { setglobal COMPREPLY = '( '$( compgen -W "$( hcitool scan | \ awk '/^\t/{print $1}' )" -- "$cur" ) ) } } proc _bluetooth_devices { setglobal COMPREPLY = '( '$( compgen -W "$( hcitool dev | \ awk '/^\t/{print $1}' )" -- "$cur" ) ) } proc _bluetooth_services { setglobal 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 { setglobal COMPREPLY = '( '$( compgen -W 'DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3' \ -- "$cur" ) ) } proc _hcitool { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with -i _bluetooth_devices return 0 with --role setglobal COMPREPLY = '( '$( compgen -W 'm s' -- "$cur" ) ) return 0 with --pkt-type _bluetooth_packet_types return 0 } $split && return 0 var arg = '' _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setglobal 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 { var args = '' match $arg { with name|info|dc|rssi|lq|afh|auth|key|clkoff|lst _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } with cc if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '--role --pkt-type' -- "$cur" ) ) } else { _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } } with sr _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } else { setglobal COMPREPLY = '( '$( compgen -W 'master slave' -- "$cur" ) ) } with cpt _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } else { _bluetooth_packet_types } with tpl|enc|clock _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } else { setglobal COMPREPLY = '( '$( compgen -W '0 1' -- "$cur" ) ) } } } } && complete -F _hcitool hcitool proc _sdptool { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with --bdaddr _bluetooth_adresses return 0 } $split && return 0 var arg = '' _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setglobal COMPREPLY = '( '$( compgen -W 'search browse records add del get setattr setseq' -- "$cur" ) ) } } else { match $arg { with search if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '--bdaddr --tree --raw --xml' \ -- "$cur" ) ) } else { _bluetooth_services } with browse|records if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '--tree --raw --xml' -- "$cur" ) ) } else { _bluetooth_adresses } with add if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '--handle --channel' -- "$cur" ) ) } else { _bluetooth_services } with get if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '--bdaddr --tree --raw --xml' \ -- "$cur" ) ) } } } } && complete -F _sdptool sdptool proc _l2ping { var cur = '', prev = '', words = '', cword = '' _init_completion || return match $prev { with -i _bluetooth_devices return 0 with -s|-c|-t|-d return 0 } if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_usage "$1" )' -- "$cur" ) ) } else { _bluetooth_adresses } } && complete -F _l2ping l2ping proc _rfcomm { var cur = '', prev = '', words = '', cword = '' _init_completion || return match $prev { with -f|--config _filedir return 0 with -i _bluetooth_devices _bluetooth_adresses return 0 } var arg = '' _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setglobal COMPREPLY = '( '$( compgen -W 'show connect listen watch bind release' -- "$cur" ) ) } } else { var args = '' _count_args if [[ $args -eq 2 ]] { _bluetooth_devices } else { match $arg { with connect|bind if [[ $args -eq 3 ]] { _bluetooth_adresses } } } } } && complete -F _rfcomm rfcomm proc _ciptool { var cur = '', prev = '', words = '', cword = '' _init_completion || return match $prev { with -i _bluetooth_devices _bluetooth_adresses return 0 } var arg = '' _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { setglobal COMPREPLY = '( '$( compgen -W 'show search connect release loopback' \ -- "$cur" ) ) } } else { var args = '' match $arg { with connect|release|loopback _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } } } } && complete -F _ciptool ciptool proc _dfutool { var cur = '', prev = '', words = '', cword = '' _init_completion || return match $prev { with -d|--device _bluetooth_devices return 0 } if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) } else { var args = '' _count_args match $args { with 1 setglobal COMPREPLY = '( '$( compgen -W 'verify modify upgrade archive' \ -- "$cur" ) ) with 2 _filedir } } } && complete -F _dfutool dfutool proc _hciconfig { var cur = '', prev = '', words = '', cword = '' _init_completion || return var arg = '' _get_first_arg if [[ -z $arg ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '--help --all' -- "$cur" ) ) } else { setglobal 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 { var args = '' match $arg { with putkey|delkey _count_args if [[ $args -eq 2 ]] { _bluetooth_adresses } with lm _count_args if [[ $args -eq 2 ]] { setglobal COMPREPLY = '( '$( compgen -W 'MASTER SLAVE NONE ACCEPT' \ -- "$cur" ) ) } with ptype _count_args if [[ $args -eq 2 ]] { _bluetooth_packet_types } } } } && complete -F _hciconfig hciconfig proc _hciattach { var cur = '', prev = '', words = '', cword = '' _init_completion || return if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '-n -p -t -b -s -l' -- "$cur" ) ) } else { var args = '' _count_args match $args { with 1 setglobal COMPREPLY = '( '$( printf '%s\n' /dev/tty* ) ) setglobal COMPREPLY = '( '$( compgen -W '${COMPREPLY[@]} ${COMPREPLY[@]#/dev/}' -- "$cur" ) ) with 2 setglobal COMPREPLY = '( '$( compgen -W 'any ericsson digi xircom csr bboxes swave bcsp 0x0105 0x080a 0x0160 0x0002' -- "$cur" ) ) with 3 setglobal COMPREPLY = '( '$( compgen -W '9600 19200 38400 57600 115200 230400 460800 921600' -- "$cur" ) ) with 4 setglobal COMPREPLY = '( '$( compgen -W 'flow noflow' -- "$cur" ) ) with 5 _bluetooth_adresses } } } && complete -F _hciattach hciattach # ex: ts=4 sw=4 et filetype=sh