/etc/zsh/zshrc: added zstyle for url-quote-magic
[grml-etc-core.git] / etc / zsh / completion.d / iwconfig
1 _wlan_interfaces() {
2     local intf
3     intf=$(iwconfig |& egrep 'IEEE 802.11[abg]' | cut -d' ' -f1 | tr ' ' \\n )
4     # intf=$( fgrep ': ' < /proc/net/wireless | cut -d: -f1 | tr \\n ' ' | tr -s " \t" )
5     _wanted interfaces expl 'wireless network interface' \
6         compadd ${intf}
7 }
8
9 _wlan_networks() {
10     networks=()
11     while read LINE
12     do
13         networks+=$LINE
14     done <<(iwlist scanning 2>/dev/null | grep ESSID | sed -e s/'.*"\(.*\)"'/'\1'/ )
15     _wanted -x names expl 'network name' \
16         compadd off any on ${networks}
17 }
18
19 _iwconfig() {
20   local curcontext="$curcontext" state line expl ret=1
21
22   _arguments -C \
23     '(1 * -)--help[display help information]' \
24     '(1 * -)--version[display version information]' \
25     '1:network interface:_wlan_interfaces' \
26     '*:parameter:->parameters' && ret=0
27
28   if [[ -n "$state" ]]; then
29     local -a arg
30
31     case $words[CURRENT-1] in
32       essid) _wlan_networks;;
33       nwid|domain) _message -e ids 'network id' ;;
34       freq|channel) _message -e channels 'channel or frequency' ;;
35       sens) _message -e levels 'signal level' ;;
36       mode)
37         _wanted modes expl 'operating mode' compadd \
38             Ad-Hoc Managed Master Repeater Secondary Monitor Auto
39       ;;
40       ap) _message -e access-points 'access point' ;;
41       nick*) _message -e names 'nickname' ;;
42       rate|bit*) _message -e bit-rates 'bit rate' ;;
43       rts*|frag*) _message -e sizes 'size' ;;
44       key|enc*) _message -e keys 'key' ;;
45       power)
46         arg=(
47           \*{min,max}'[modifier]'
48       '*off[disable power management]'
49       '*on[enable power management]'
50       '*all[receive all packets]'
51       'unicast[receive unicast packets only]'
52       'multicast[receive multicast and broadcast packets only]'
53         )
54       ;&
55       min|max)
56         _values -S ' ' -w 'parameter' \
57           'period[set the period between wake ups]' \
58       'timeout[set timeout before sleep]' \
59       $arg[@] && ret=0
60       ;;
61       period|timeout) _message -e timeouts 'timeout' ;;
62       txpower) _message -e power 'transmit power' ;;
63       retry) _message -e retries 'retries' ;;
64       *)
65         _values -S ' ' -w 'option' \
66           'essid[set the network name]' \
67       '(nwid domain)'{nwid,domain}'[set the network ID]' \
68       '(freq channel)'{freq,channel}'[set the operating frequency or channel]' \
69       'sens[set the sensitivity threhold]' \
70           'mode[set operating mode]' \
71       'ap[register with given access point]' \
72       '(nick nickname)'nick{,name}'[set the nickname]' \
73       '(rate bit)'{rate,bit}'[set the bitrate]' \
74       'rts[set packet size threshold for sending RTS]' \
75       'frag[set maximum packet fragment size]' \
76       \*{key,enc}'[add encryption key]' \
77       '*power[manipulate power management scheme parameters]' \
78       'txpower[set transmit power]' \
79       'retry[set number of retries]' \
80       'commit[apply changes imediately]' && ret=0
81       ;;
82     esac
83   fi
84
85   return ret
86 }
87
88 compdef _iwconfig iwconfig