PageRenderTime 43ms CodeModel.GetById 37ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/bluez-utils

http://github.com/brinkman83/bashrc
#! | 452 lines | 403 code | 49 blank | 0 comment | 0 complexity | c716ccc77460d4736ba4dd5f4f0a3a97 MD5 | raw file
  1# bash completion for bluez-utils
  2
  3have hcitool && {
  4_bluetooth_adresses()
  5{
  6    if [ -n "${COMP_BLUETOOTH_SCAN:-}" ]; then
  7        COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -W "$( hcitool scan | \
  8            awk '/^\t/{print $1}' )" -- "$cur" ) )
  9    fi
 10}
 11
 12_bluetooth_devices()
 13{
 14    COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -W "$( hcitool dev | \
 15        awk '/^\t/{print $1}' )" -- "$cur" ) )
 16}
 17
 18_bluetooth_services()
 19{
 20    COMPREPLY=( $( compgen -W 'DID SP DUN LAN FAX OPUSH FTP HS HF HFAG \
 21        SAP NAP GN PANU HCRP HID CIP A2SRC A2SNK AVRCT AVRTG UDIUE \
 22        UDITE SYNCML' -- "$cur" ) )
 23}
 24
 25_bluetooth_packet_types()
 26{
 27    COMPREPLY=( $( compgen -W 'DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3' \
 28        -- "$cur" ) )
 29}
 30
 31_get_command()
 32{
 33    local i
 34
 35    command=
 36    for (( i=1; i < COMP_CWORD; i++ )); do
 37        if [[ "${COMP_WORDS[i]}" != -* ]]; then
 38            command=${COMP_WORDS[i]}
 39            break
 40        fi
 41    done
 42}
 43
 44_hcitool()
 45{
 46    local cur prev split=false
 47
 48    COMPREPLY=()
 49    cur=`_get_cword`
 50    prev=${COMP_WORDS[COMP_CWORD-1]}
 51
 52    _split_longopt && split=true
 53
 54    case $prev in
 55        -i)
 56            _bluetooth_devices
 57            return 0;
 58            ;;
 59        --role)
 60            COMPREPLY=( $( compgen -W 'm s' -- "$cur" ) )
 61            return 0;
 62            ;;
 63        --pkt-type)
 64            _bluetooth_packet_types
 65            return 0;
 66            ;;
 67    esac
 68
 69    $split && return 0
 70
 71    _get_command
 72    if [ -z $command ]; then
 73        if [[ "$cur" == -* ]]; then
 74            COMPREPLY=( $( compgen -W '-h -i' -- "$cur" ) )
 75        else
 76            COMPREPLY=( $( compgen -W 'dev inq scan name info \
 77                spinq epinq cmd con cc dc sr cpt rssi lq tpl \
 78                afh lst auth enc key clkoff clock' -- "$cur" ) )
 79        fi
 80    else
 81        case $command in
 82            @(name|info|dc|rssi|lq|afh|auth|key|clkoff|lst))
 83                _count_args
 84                if [ $args -eq 2 ]; then
 85                    _bluetooth_adresses
 86                fi
 87                ;;
 88            cc)
 89                if [[ "$cur" == -* ]]; then
 90                    COMPREPLY=( $( compgen -W '--role --pkt-type' -- "$cur" ) )
 91                else
 92                    _count_args
 93                    if [ $args -eq 2 ]; then
 94                        _bluetooth_adresses
 95                    fi
 96                fi
 97                ;;
 98            sr)
 99                _count_args
100                if [ $args -eq 2 ]; then
101                    _bluetooth_adresses
102                else
103                    COMPREPLY=( $( compgen -W 'master slave' -- "$cur" ) )
104                fi
105                ;;
106            cpt)
107                _count_args
108                if [ $args -eq 2 ]; then
109                    _bluetooth_adresses
110                else
111                    _bluetooth_packet_types
112                fi
113                ;;
114            @(tpl|enc|clock))
115                _count_args
116                if [ $args -eq 2 ]; then
117                    _bluetooth_adresses
118                else
119                    COMPREPLY=( $( compgen -W '0 1' -- "$cur" ) )
120                fi
121                ;;
122        esac
123    fi
124}
125complete -F _hcitool hcitool
126
127_sdptool()
128{
129    local cur prev split=false
130
131    COMPREPLY=()
132    cur=`_get_cword`
133    prev=${COMP_WORDS[COMP_CWORD-1]}
134
135    _split_longopt && split=true
136
137    case $prev in
138        --bdaddr)
139            _bluetooth_adresses
140            return 0;
141            ;;
142    esac
143
144    $split && return 0
145
146    _get_command
147    if [ -z $command ]; then
148        if [[ "$cur" == -* ]]; then
149            COMPREPLY=( $( compgen -W '--help' -- "$cur" ) )
150        else
151            COMPREPLY=( $( compgen -W 'search browse records add \
152                del get setattr setseq' -- "$cur" ) )
153        fi
154    else
155        case $command in
156            search)
157                if [[ "$cur" == -* ]]; then
158                    COMPREPLY=( $( compgen -W '--bdaddr \
159                        --tree --raw --xml' -- "$cur" ) )
160                else
161                    _bluetooth_services
162                fi
163                ;;
164            @(browse|records))
165                if [[ "$cur" == -* ]]; then
166                    COMPREPLY=( $( compgen -W '--tree --raw --xml' -- "$cur" ) )
167                else
168                    _bluetooth_adresses
169                fi
170                ;;
171            add)
172                if [[ "$cur" == -* ]]; then
173                    COMPREPLY=( $( compgen -W '--handle --channel' -- "$cur" ) )
174                else
175                    _bluetooth_services
176                fi
177                ;;
178            get)
179                if [[ "$cur" == -* ]]; then
180                    COMPREPLY=( $( compgen -W '--bdaddr \
181                        --tree --raw --xml' -- "$cur" ) )
182                fi
183                ;;
184        esac
185    fi
186}
187complete -F _sdptool sdptool
188
189_l2ping()
190{
191    local cur prev
192
193    COMPREPLY=()
194    cur=`_get_cword`
195    prev=${COMP_WORDS[COMP_CWORD-1]}
196
197    case $prev in
198        -i)
199            _bluetooth_devices
200            return 0;
201            ;;
202    esac
203
204    if [[ "$cur" == -* ]]; then
205        COMPREPLY=( $( compgen -W '-i -s -c -t -f -r' -- "$cur" ) )
206    else
207        _bluetooth_adresses
208    fi
209
210}
211complete -F _l2ping l2ping
212
213_rfcomm()
214{
215    local cur prev
216
217    COMPREPLY=()
218    cur=`_get_cword`
219    prev=${COMP_WORDS[COMP_CWORD-1]}
220
221    case $prev in
222        -@(f|-config))
223            _filedir
224            return 0;
225            ;;
226        -i)
227            _bluetooth_devices
228            _bluetooth_adresses
229            return 0;
230            ;;
231    esac
232
233    _get_command
234    if [ -z $command ]; then
235        if [[ "$cur" == -* ]]; then
236            COMPREPLY=( $( compgen -W '-h --help -a -r --raw -f \
237                --config -i -A --auth -E --encrypt -S --secure \
238                -M --master' -- "$cur" ) )
239        else
240            COMPREPLY=( $( compgen -W 'show connect listen watch \
241                bind release' -- "$cur" ) )
242        fi
243    else
244        _count_args
245        if [ $args -eq 2 ]; then
246            _bluetooth_devices
247        else
248            case $command in
249                @(connect|bind))
250                    if [ $args -eq 3 ]; then
251                        _bluetooth_adresses
252                    fi
253                    ;;
254            esac
255        fi
256    fi
257}
258complete -F _rfcomm rfcomm
259
260_ciptool()
261{
262    local cur prev
263
264    COMPREPLY=()
265    cur=`_get_cword`
266    prev=${COMP_WORDS[COMP_CWORD-1]}
267
268    case $prev in
269        -i)
270            _bluetooth_devices
271            _bluetooth_adresses
272            return 0;
273            ;;
274    esac
275
276    _get_command
277    if [ -z $command ]; then
278        if [[ "$cur" == -* ]]; then
279            COMPREPLY=( $( compgen -W '-h --help -i' -- "$cur" ) )
280        else
281            COMPREPLY=( $( compgen -W 'show search connect release \
282                loopback' -- "$cur" ) )
283        fi
284    else
285        case $command in
286            @(connect|release|loopback))
287                _count_args
288                if [ $args -eq 2 ]; then
289                    _bluetooth_adresses
290                fi
291                ;;
292        esac
293    fi
294}
295complete -F _ciptool ciptool
296
297_dfutool()
298{
299    local cur prev
300
301    COMPREPLY=()
302    cur=`_get_cword`
303    prev=${COMP_WORDS[COMP_CWORD-1]}
304
305    case $prev in
306        -@(d|-device))
307            _bluetooth_devices
308            return 0;
309            ;;
310    esac
311
312    if [[ "$cur" == -* ]]; then
313        COMPREPLY=( $( compgen -W '-h --help -d --device' -- "$cur" ) )
314    else
315        _count_args
316        case $args in
317            1)
318                COMPREPLY=( $( compgen -W 'verify modify \
319                    upgrade archive' -- "$cur" ) )
320                ;;
321            2)
322                _filedir
323                ;;
324        esac
325    fi
326}
327complete -F _dfutool dfutool
328
329_hciconfig()
330{
331    local cur
332
333    COMPREPLY=()
334    cur=`_get_cword`
335
336    _get_command
337    if [ -z $command ]; then
338        if [[ "$cur" == -* ]]; then
339            COMPREPLY=( $( compgen -W '-h --help -a --all' -- "$cur" ) )
340        else
341            COMPREPLY=( $( compgen -W 'up down reset rstat auth \
342                noauth encrypt noencrypt secmgr nosecmgr \
343                piscan noscan iscan pscan ptype name class \
344                voice iac inqmode inqdata inqtype inqparams \
345                pageparms pageto afhmode aclmtu scomtu putkey \
346                delkey commands features version revision lm' \
347                -- "$cur" ) )
348        fi
349    else
350        case $command in
351            @(putkey|delkey))
352                _count_args
353                if [ $args -eq 2 ]; then
354                    _bluetooth_adresses
355                fi
356                ;;
357            lm)
358                _count_args
359                if [ $args -eq 2 ]; then
360                    COMPREPLY=( $( compgen -W 'MASTER \
361                        SLAVE NONE ACCEPT' -- "$cur" ) )
362                fi
363                ;;
364            ptype)
365                _count_args
366                if [ $args -eq 2 ]; then
367                    _bluetooth_packet_types
368                fi
369                ;;
370        esac
371    fi
372}
373complete -F _hciconfig hciconfig
374
375_hciattach()
376{
377    local cur
378
379    COMPREPLY=()
380    cur=`_get_cword`
381
382    if [[ "$cur" == -* ]]; then
383        COMPREPLY=( $( compgen -W '-n -p -t -b -s -l' -- "$cur" ) )
384    else
385        _count_args
386        case $args in
387            1)
388                COMPREPLY=( $( command ls /dev/tty* ) )
389                COMPREPLY=( $( compgen -W '${COMPREPLY[@]} \
390                    ${COMPREPLY[@]#/dev/}' -- "$cur" ) )
391                ;;
392            2)
393                COMPREPLY=( $( compgen -W 'any ericsson digi \
394                    xircom csr bboxes swave bcsp 0x0105 \
395                    0x080a 0x0160 0x0002' -- "$cur" ) )
396                ;;
397            3)
398                COMPREPLY=( $( compgen -W '9600 19200 38400 \
399                    57600 115200 230400 460800 921600' -- "$cur" ) )
400                ;;
401            4)
402                COMPREPLY=( $( compgen -W 'flow noflow' -- "$cur" ) )
403                ;;
404            5)
405                _bluetooth_adresses
406                ;;
407        esac
408    fi
409
410}
411complete -F _hciattach hciattach
412
413_hid2hci()
414{
415    local cur
416
417    COMPREPLY=()
418    cur=`_get_cword`
419
420    if [[ "$cur" == -* ]]; then
421        COMPREPLY=( $( compgen -W '-h --help -q --quiet -0 --tohci -1 \
422            --tohid' -- "$cur" ) )
423    fi
424}
425complete -F _hid2hci hid2hci
426
427_avctrl()
428{
429    local cur
430
431    COMPREPLY=()
432    cur=`_get_cword`
433
434    if [[ "$cur" == -* ]]; then
435        COMPREPLY=( $( compgen -W '-h --help -q --quiet' -- "$cur" ) )
436    else
437        _count_args
438        if [ $args -eq 1 ]; then
439            COMPREPLY=( $( compgen -W 'discover switch' -- "$cur" ) )
440        fi
441    fi
442}
443complete -F _avctrl avctrl
444}
445
446# Local variables:
447# mode: shell-script
448# sh-basic-offset: 4
449# sh-indent-comment: t
450# indent-tabs-mode: nil
451# End:
452# ex: ts=4 sw=4 et filetype=sh