fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge branch 'completions-to-use-expanded-tokens'a9618477e

master
12.5 KiB291 linesraw
1# iw(8) completion for fish
2
3# The completions for iw are based off those for ip, which has a similar options structure.
4
5set -l iw_commands dev phy reg event features commands list
6# wdev not supported since it is barely documented
7
8function __fish_iw_device
9    __fish_print_interfaces | while read -l i
10        printf '%s\t%s\n' $i Device
11    end
12end
13
14function __fish_iw_phy
15    set -l phys /sys/class/ieee80211/*
16    string match --regex '[^/]*$' $phys
17end
18
19function __fish_iw_ssid
20    printf '%s\n' (iw dev $argv[1] scan dump | string match --regex --entire SSID | string split ' ')[2]
21end
22
23function __fish_complete_iw
24    set -l cmd (commandline -xpc)
25
26    if string match --quiet -- '-*' $cmd[2]
27        set -e cmd[2] # Allow other completions to complete as normal
28    end
29    if not set -q cmd[2]
30        return # Uses completions from $iw_commands
31    else if not set -q cmd[3]
32        switch $cmd[2]
33            case dev
34                __fish_iw_device
35            case phy
36                __fish_iw_phy
37        end
38        return
39    end
40    switch $cmd[2]
41        case dev
42            switch "$cmd[4]"
43                case ap
44                    if not set -q cmd[5]
45                        printf '%s\t%s\n' stop "Stop AP functionality" \
46                            start "Start AP functionality"
47                    end
48                case auth connect
49                    if not set -q cmd[5]
50                        __fish_iw_ssid $cmd[3]
51                    end
52                case disconnect
53                case cqm
54                    if not set -q cmd[5]
55                        echo rssi
56                    else if not set -q cmd[6]
57                        echo threshold
58                        echo off
59                    end
60                case ftm
61                    if not set -q cmd[5]
62                        printf '%s\t%s\n' start_responder "Start an FTM responder" \
63                            get_stats "Get FTM responder statistics"
64                    end
65                case ibss
66                    if not set -q cmd[5]
67                        printf '%s\t%s\n' join "Join an IBSS cell or create one" \
68                            leave "Leave the current IBSS cell"
69                    end
70                case switch
71                    if not set -q cmd[5]
72                        echo channel
73                        echo freq
74                    end
75                case info del
76                case interface
77                    if not set -q cmd[5]
78                        echo add
79                    end
80                case link
81                case measurement
82                    if not set -q cmd[5]
83                        echo ftm_request
84                    else if not set -q cmd[6]
85                        __fish_complete_path
86                    end
87                    # options after config file?
88                case mesh
89                    if not set -q cmd[5]
90                        printf '%s\t%s\n' leave "Leave a mesh" \
91                            join "Join a mesh"
92                    end
93                case mgmt
94                    if not set -q cmd[5]
95                        echo dump
96                    else if not set -q cmd[6]
97                        echo frame
98                    end
99                case mpath
100                    if not set -q cmd[5]
101                        printf '%s\t%s\n' dump "List known mesh paths" \
102                            set "Set an existing mesh path's next hop" \
103                            new "Create a new mesh math manually" \
104                            del "Remove the mesh path to a node" \
105                            get "Get information on a mesh path to a node" \
106                            probe "Inject ethernet frame to a peer"
107                    end
108                case mpp
109                    if not set -q cmd[5]
110                        printf '%s\t%s\n' dump "List known mesh proxy paths" \
111                            get "Get information on mesh proxy path to a node"
112                    end
113                case ocb
114                    if not set -q cmd[5]
115                        printf '%s\t%s\n' leave "Leave the OCB mode network" \
116                            join "Join the OCB mode network"
117                    end
118                case cac
119                    if not set -q cmd[5]
120                        echo channel
121                        echo freq
122                        echo trigger
123                    end
124                case roc
125                    if not set -q cmd[5]
126                        echo start
127                    end
128                case scan
129                    if not set -q cmd[5]
130                        printf '%s\t%s\n' sched_stop "Stop an ongoing scheduled scan" \
131                            sched_start "Start a scheduled scan" \
132                            abort "Abort ongoing scan" \
133                            trigger "Trigger a scan" \
134                            dump "Dmp the current scan results"
135                    end
136                    # -u option?
137                case set
138                    if not set -q cmd[5]
139                        printf '%s\t%s\n' bitrates "Rate masks" \
140                            mcast_rate "Multicast bitrate" \
141                            peer "WDS peer" \
142                            noack_map "Noack map for TIDs" \
143                            4addr "4addr (WDS) mode" \
144                            type "Interface type/mode" \
145                            meshid "" \
146                            monitor "Monitor flags" \
147                            mesh_param "Mesh parameter" \
148                            txpower "Transmit power" \
149                            channel "" \
150                            freq "" \
151                            power_save "Power save state"
152                    else
153                        switch "$cmd[5]"
154                            case type
155                                if not set -q cmd[6]
156                                    printf '%s\n' managed ibss monitor mesh wds
157                                end
158                            case channel
159                                if not set -q cmd[6]
160                                    # cmd[6] is just the simple channel number
161                                else if not set -q cmd[7]
162                                    printf '%s\n' NOHT HT20 HT40+ HT40- 5MHz 10MHz 80MHz 160MHz
163                                end
164                        end
165                    end
166                case get
167                    if not set -q cmd[5]
168                        printf '%s\t%s\n' mesh_param "Mesh parameter" \
169                            power_save "Power save state"
170                    end
171                case station
172                    if not set -q cmd[5]
173                        printf '%s\t%s\n' dump "List all stations known" \
174                            set "Set station options" \
175                            del "Remove a station entry" \
176                            get "Get information for a station"
177                    end
178                case survey
179                    if not set -q cmd[5]
180                        echo dump
181                    end
182                case vendor
183                    if not set -q cmd[5]
184                        echo recvbin
185                        echo recv
186                        echo send
187                    end
188                case '*'
189                    printf '%s\t%s\n' ap "Start/stop AP functionality" \
190                        auth "Authenticate with a network" \
191                        connect "Join a network" \
192                        disconnect "Disconnect from the current network" \
193                        cqm "Set connection quality monitor RSSI threshold" \
194                        ftm "Control the FTM responder" \
195                        ibss "Join or leave a IBSS cell" \
196                        switch "Switch the operating channel by sending a CSA" \
197                        info "Show information for this interface" \
198                        del "Remove this virtual interface" \
199                        interface "Control the interface" \
200                        link "Print information about the current link" \
201                        measurement "Perform measurements" \
202                        mesh "Join or leave a mesh" \
203                        mpp "Get information on mesh proxy paths" \
204                        mgmt "Print mgmt frames" \
205                        mpath "Interact with mesh paths" \
206                        ocb "Join or leave an OCB mode network" \
207                        offchannel "Leave operating channel" \
208                        cac "Start or trigger a channel availability chec" \
209                        roc "" \
210                        scan "Scan and probe for SSIDs" \
211                        set "Set parameters" \
212                        get "Get parameters" \
213                        station "Set station parameters" \
214                        survey "List all gathered channel survey data" \
215                        vendor ""
216            end
217        case phy
218            switch "$cmd[4]"
219                case coalesce
220                    if not set -q cmd[5]
221                        printf '%s\t%s\n' show "Show coalesce status" \
222                            disable "Disable coalesce" \
223                            enable "Enable coalesce"
224                    else if test "$cmd[5]" = enable && not set -q cmd[6]
225                        __fish_complete_path # Enable takes a config file
226                    end
227                case hwsim
228                    if not set -q cmd[5]
229                        printf '%s\n' wakequeues stopqueues setps getps
230                    end
231                case info
232                case interface
233                    if not set -q cmd[5]
234                        echo add
235                    end
236                case channels
237                case reg
238                    if not set -q cmd[5]
239                        printf '%s\t%s\n' get "Print the current regulatory domain information" \
240                            set "Notify kernel about current regulatory domain"
241                    end
242                case set
243                    if not set -q cmd[5]
244                        printf '%s\t%s\n' txq "TXQ parameters" \
245                            antenna "Bitmap of allowed antennas" \
246                            txpower "Transmit power" \
247                            distance "Link distance coverage class" \
248                            netns "Network namespace" \
249                            retry "Retry limit" \
250                            rts "Rts threshold" \
251                            frag "Fragmentation threshold" \
252                            channel "" \
253                            name "Wireless device name"
254                    end
255                case get
256                    if not set -q cmd[5]
257                        printf '%s\t%s\n' txq "TXQ parameters"
258                    end
259                case get
260                    if not set -q cmd[5]
261                        printf '%s\t%s\n' show "Show WoWLAN status" \
262                            disable "Disable WoWLAN" \
263                            enable "Enable WoWLAN"
264                    end
265                case '*'
266                    printf '%s\t%s\n' coalesce "Interface with coalesce" \
267                        hwsim "" \
268                        info "Show wireless device capabilities" \
269                        interface "Add a new virtual interface" \
270                        channels "Show available channels" \
271                        reg "Manage regulatory domains" \
272                        set "Set parameters" \
273                        get "Get parameters"
274            end
275    end
276end
277
278complete -f -c iw
279complete -f -c iw -a '(__fish_complete_iw)'
280complete -f -c iw -n "not __fish_seen_subcommand_from $iw_commands" -a "$iw_commands"
281# Yes, iw only takes options before "objects"
282complete -f -c iw -l debug -d "Enable netlink message debugging" -n "not __fish_seen_subcommand_from $iw_commands"
283complete -f -c iw -l version -d "Print the version" -n "not __fish_seen_subcommand_from $iw_commands"
284
285complete -f -c iw -n "__fish_seen_subcommand_from event" -s t -d 'Print timestamp'
286complete -f -c iw -n "__fish_seen_subcommand_from event" -s r -d 'Print relative timestamp'
287complete -f -c iw -n "__fish_seen_subcommand_from event" -s f -d 'Print full frame for auth/assoc'
288
289complete -f -c iw -n "__fish_seen_subcommand_from reg" -a reload -d 'Reload the kernel\'s regulatory database'
290complete -f -c iw -n "__fish_seen_subcommand_from reg" -a get -d 'Print the kernel\'s current regulatory domain information'
291complete -f -c iw -n "__fish_seen_subcommand_from reg" -a set -d 'Notify the kernel about the current regulatory domain'