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