/bash_completion.d/wireless-tools

http://github.com/brinkman83/bashrc · #! · 183 lines · 161 code · 22 blank · 0 comment · 0 complexity · 9988c688308c497c3f4fb0acc571c470 MD5 · raw file

  1. # bash completion for Linux wireless-tools
  2. [ $UNAME = Linux ] &&
  3. {
  4. have iwconfig &&
  5. _iwconfig()
  6. {
  7. local cur prev
  8. COMPREPLY=()
  9. cur=`_get_cword`
  10. prev=${COMP_WORDS[COMP_CWORD-1]}
  11. case $prev in
  12. mode)
  13. COMPREPLY=( $( compgen -W 'managed ad-hoc master \
  14. repeater secondary monitor' -- "$cur" ) )
  15. return 0
  16. ;;
  17. essid)
  18. COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
  19. if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
  20. COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W \
  21. "$( iwlist ${COMP_WORDS[1]} scan | \
  22. awk -F '\"' '/ESSID/ {print $2}' )" -- "$cur" ) )
  23. fi
  24. return 0
  25. ;;
  26. nwid)
  27. COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) )
  28. return 0
  29. ;;
  30. channel)
  31. COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \
  32. awk '/^[[:space:]]*Channel/ {print $2}' )" -- "$cur" ) )
  33. return 0
  34. ;;
  35. freq)
  36. COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \
  37. awk '/^[[:space:]]*Channel/ {print $4\"G\"}')" -- "$cur" ) )
  38. return 0
  39. ;;
  40. ap)
  41. COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
  42. if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
  43. COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W \
  44. "$( iwlist ${COMP_WORDS[1]} scan | \
  45. awk -F ': ' '/Address/ {print $2}' )" -- "$cur" ) )
  46. fi
  47. return 0
  48. ;;
  49. rate)
  50. COMPREPLY=( $( compgen -W 'auto fixed' -- "$cur" ) )
  51. COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W \
  52. "$( iwlist ${COMP_WORDS[1]} rate | \
  53. awk '/^[[:space:]]*[0-9]/ {print $1\"M\"}' )" -- "$cur" ) )
  54. return 0
  55. ;;
  56. rts|frag)
  57. COMPREPLY=( $( compgen -W 'auto fixed off' -- "$cur" ) )
  58. return 0
  59. ;;
  60. key|enc)
  61. COMPREPLY=( $( compgen -W 'off on open restricted' -- "$cur" ) )
  62. return 0
  63. ;;
  64. power)
  65. COMPREPLY=( $( compgen -W 'period timeout off on' -- "$cur" ) )
  66. return 0
  67. ;;
  68. txpower)
  69. COMPREPLY=( $( compgen -W 'off on auto' -- "$cur" ) )
  70. return 0
  71. ;;
  72. retry)
  73. COMPREPLY=( $( compgen -W 'limit lifetime' -- "$cur" ) )
  74. return 0
  75. ;;
  76. esac
  77. if [ $COMP_CWORD -eq 1 ]; then
  78. if [[ "$cur" == -* ]]; then
  79. COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
  80. else
  81. _available_interfaces -w
  82. fi
  83. else
  84. COMPREPLY=( $( compgen -W 'essid nwid mode freq channel sens mode \
  85. ap nick rate rts frag enc key power txpower commit' -- "$cur" ) )
  86. fi
  87. } &&
  88. complete -F _iwconfig iwconfig
  89. have iwlist &&
  90. _iwlist()
  91. {
  92. local cur prev
  93. COMPREPLY=()
  94. cur=`_get_cword`
  95. prev=${COMP_WORDS[COMP_CWORD-1]}
  96. if [ $COMP_CWORD -eq 1 ]; then
  97. if [[ "$cur" == -* ]]; then
  98. COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
  99. else
  100. _available_interfaces -w
  101. fi
  102. else
  103. COMPREPLY=( $( compgen -W 'scan scanning freq frequency \
  104. channel rate bit bitrate key enc encryption power \
  105. txpower retry ap accesspoint peers event' -- "$cur" ) )
  106. fi
  107. } &&
  108. complete -F _iwlist iwlist
  109. have iwspy &&
  110. _iwspy()
  111. {
  112. local cur
  113. COMPREPLY=()
  114. cur=`_get_cword`
  115. if [ $COMP_CWORD -eq 1 ]; then
  116. if [[ "$cur" == -* ]]; then
  117. COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
  118. else
  119. _available_interfaces -w
  120. fi
  121. else
  122. COMPREPLY=( $( compgen -W 'setthr getthr off' -- "$cur" ) )
  123. fi
  124. } &&
  125. complete -F _iwspy iwspy
  126. have iwpriv &&
  127. _iwpriv()
  128. {
  129. local cur prev
  130. COMPREPLY=()
  131. cur=`_get_cword`
  132. prev=${COMP_WORDS[COMP_CWORD-1]}
  133. case "$prev" in
  134. roam)
  135. COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) )
  136. return 0
  137. ;;
  138. port)
  139. COMPREPLY=( $( compgen -W 'ad-hoc managed' -- "$cur" ) )
  140. return 0
  141. ;;
  142. esac
  143. if [ $COMP_CWORD -eq 1 ]; then
  144. if [[ "$cur" == -* ]]; then
  145. COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
  146. else
  147. _available_interfaces -w
  148. fi
  149. else
  150. COMPREPLY=( $( compgen -W '--all roam port' -- "$cur" ) )
  151. fi
  152. } &&
  153. complete -F _iwpriv iwpriv
  154. }
  155. # Local variables:
  156. # mode: shell-script
  157. # sh-basic-offset: 4
  158. # sh-indent-comment: t
  159. # indent-tabs-mode: nil
  160. # End:
  161. # ex: ts=4 sw=4 et filetype=sh