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