Skip to content

Commit a06225f

Browse files
KaiSforzakeszybz
authored andcommitted
zsh_completion: Split out zsh _udevadm
1 parent 20c8382 commit a06225f

File tree

3 files changed

+143
-141
lines changed

3 files changed

+143
-141
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ dist_bashcompletion_DATA = \
346346
dist_zshcompletion_DATA = \
347347
shell-completion/zsh/_systemctl \
348348
shell-completion/zsh/_journalctl \
349+
shell-completion/zsh/_udevadm \
349350
shell-completion/zsh/_systemd
350351

351352
dist_sysctl_DATA = \

shell-completion/zsh/_systemd

Lines changed: 1 addition & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
#compdef udevadm systemd-analyze systemd-cat systemd-ask-password systemd-cgls systemd-cgtop systemd-delta systemd-detect-virt systemd-inhibit systemd-machine-id-setup systemd-notify systemd-nspawn systemd-tmpfiles systemd-tty-ask-password-agent machinectl
1+
#compdef systemd-analyze systemd-cat systemd-ask-password systemd-cgls systemd-cgtop systemd-delta systemd-detect-virt systemd-inhibit systemd-machine-id-setup systemd-notify systemd-nspawn systemd-tmpfiles systemd-tty-ask-password-agent machinectl
22

33
_ctls()
44
{
55
local curcontext="$curcontext" state lstate line
66
case "$service" in
7-
udevadm)
8-
_arguments \
9-
'--debug[Print debug messages to stderr]' \
10-
'--version[Print version number]' \
11-
'--help[Print help text]' \
12-
'*::udevadm commands:_udevadm_command'
13-
;;
147
systemd-analyze)
158
_arguments \
169
{-h,--help}'[Show help text.]' \
@@ -247,139 +240,6 @@ _outputmodes() {
247240
fi
248241
}
249242

250-
_udevadm_info(){
251-
_arguments \
252-
'--query=[Query the database for specified type of device data. It needs the --path or --name to identify the specified device.]:type:(name symlink path property all)' \
253-
'--path=[The devpath of the device to query.]:sys files:_files -P /sys/ -W /sys' \
254-
'--name=[The name of the device node or a symlink to query]:device files:_files -P /dev/ -W /dev' \
255-
'--root[Print absolute paths in name or symlink query.]' \
256-
'--attribute-walk[Print all sysfs properties of the specified device that can be used in udev rules to match the specified device]' \
257-
'--export[Print output as key/value pairs.]' \
258-
'--export-prefix=[Add a prefix to the key name of exported values.]:prefix' \
259-
'--device-id-of-file=[Print major/minor numbers of the underlying device, where the file lives on.]:files:_udevadm_mounts' \
260-
'--export-db[Export the content of the udev database.]' \
261-
'--cleanup-db[Cleanup the udev database.]'
262-
}
263-
264-
_udevadm_trigger(){
265-
_arguments \
266-
'--verbose[Print the list of devices which will be triggered.]' \
267-
'--dry-run[Do not actually trigger the event.]' \
268-
'--type=[Trigger a specific type of devices.]:types:(devices subsystems failed)' \
269-
'--action=[Type of event to be triggered.]:actions:(add change remove)' \
270-
'--subsystem-match=[Trigger events for devices which belong to a matching subsystem.]' \
271-
'--subsystem-nomatch=[Do not trigger events for devices which belong to a matching subsystem.]' \
272-
'--attr-match=attribute=[Trigger events for devices with a matching sysfs attribute.]' \
273-
'--attr-nomatch=attribute=[Do not trigger events for devices with a matching sysfs attribute.]' \
274-
'--property-match=[Trigger events for devices with a matching property value.]' \
275-
'--tag-match=property[Trigger events for devices with a matching tag.]' \
276-
'--sysname-match=[Trigger events for devices with a matching sys device name.]' \
277-
'--parent-match=[Trigger events for all children of a given device.]'
278-
}
279-
280-
_udevadm_settle(){
281-
_arguments \
282-
'--timeout=[Maximum number of seconds to wait for the event queue to become empty.]' \
283-
'--seq-start=[Wait only for events after the given sequence number.]' \
284-
'--seq-end=[Wait only for events before the given sequence number.]' \
285-
'--exit-if-exists=[Stop waiting if file exists.]:files:_files' \
286-
'--quiet[Do not print any output, like the remaining queue entries when reaching the timeout.]' \
287-
'--help[Print help text.]'
288-
}
289-
290-
_udevadm_control(){
291-
_arguments \
292-
'--exit[Signal and wait for systemd-udevd to exit.]' \
293-
'--log-priority=[Set the internal log level of systemd-udevd.]:priorities:(err info debug)' \
294-
'--stop-exec-queue[Signal systemd-udevd to stop executing new events. Incoming events will be queued.]' \
295-
'--start-exec-queue[Signal systemd-udevd to enable the execution of events.]' \
296-
'--reload[Signal systemd-udevd to reload the rules files and other databases like the kernel module index.]' \
297-
'--property=[Set a global property for all events.]' \
298-
'--children-max=[Set the maximum number of events.]' \
299-
'--timeout=[The maximum number of seconds to wait for a reply from systemd-udevd.]' \
300-
'--help[Print help text.]'
301-
}
302-
303-
_udevadm_monitor(){
304-
_arguments \
305-
'--kernel[Print the kernel uevents.]' \
306-
'--udev[Print the udev event after the rule processing.]' \
307-
'--property[Also print the properties of the event.]' \
308-
'--subsystem-match=[Filter events by subsystem/\[devtype\].]' \
309-
'--tag-match=[Filter events by property.]' \
310-
'--help[Print help text.]'
311-
}
312-
313-
_udevadm_test(){
314-
_arguments \
315-
'--action=[The action string.]:actions:(add change remove)' \
316-
'--subsystem=[The subsystem string.]' \
317-
'--help[Print help text.]' \
318-
'*::devpath:_files -P /sys/ -W /sys'
319-
}
320-
321-
_udevadm_test-builtin(){
322-
if (( CURRENT == 2 )); then
323-
_arguments \
324-
'--help[Print help text]' \
325-
'*::builtins:(blkid btrfs hwdb input_id kmod path_id usb_id uaccess)'
326-
elif (( CURRENT == 3 )); then
327-
_arguments \
328-
'--help[Print help text]' \
329-
'*::syspath:_files -P /sys -W /sys'
330-
else
331-
_arguments \
332-
'--help[Print help text]'
333-
fi
334-
}
335-
336-
_udevadm_mounts(){
337-
local dev_tmp dpath_tmp mp_tmp mline
338-
339-
tmp=( "${(@f)$(< /etc/mtab)}" )
340-
dev_tmp=( "${(@)${(@)tmp%% *}:#none}" )
341-
mp_tmp=( "${(@)${(@)tmp#* }%% *}" )
342-
343-
local MATCH
344-
mp_tmp=("${(@q)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}")
345-
dpath_tmp=( "${(@Mq)dev_tmp:#/*}" )
346-
dev_tmp=( "${(@q)dev_tmp:#/*}" )
347-
348-
_alternative \
349-
'device-paths: device path:compadd -a dpath_tmp' \
350-
'directories:mount point:compadd -a mp_tmp'
351-
}
352-
353-
354-
_udevadm_command(){
355-
local -a _udevadm_cmds
356-
_udevadm_cmds=(
357-
'info:query sysfs or the udev database'
358-
'trigger:request events from the kernel'
359-
'settle:wait for the event queue to finish'
360-
'control:control the udev daemon'
361-
'monitor:listen to kernel and udev events'
362-
'test:test an event run'
363-
'test-builtin:test a built-in command'
364-
)
365-
366-
if ((CURRENT == 1)); then
367-
_describe -t commands 'udevadm commands' _udevadm_cmds
368-
else
369-
local curcontext="$curcontext"
370-
cmd="${${_udevadm_cmds[(r)$words[1]:*]%%:*}}"
371-
if (($#cmd)); then
372-
if (( $+functions[_udevadm_$cmd] )); then
373-
_udevadm_$cmd
374-
else
375-
_message "no options for $cmd"
376-
fi
377-
else
378-
_message "no more options"
379-
fi
380-
fi
381-
}
382-
383243
_ctls "$@"
384244

385245
#vim: set ft=zsh sw=4 ts=4 et

shell-completion/zsh/_udevadm

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#compdef udevadm
2+
3+
_udevadm_info(){
4+
_arguments \
5+
'--query=[Query the database for specified type of device data. It needs the --path or --name to identify the specified device.]:type:(name symlink path property all)' \
6+
'--path=[The devpath of the device to query.]:sys files:_files -P /sys/ -W /sys' \
7+
'--name=[The name of the device node or a symlink to query]:device files:_files -P /dev/ -W /dev' \
8+
'--root[Print absolute paths in name or symlink query.]' \
9+
'--attribute-walk[Print all sysfs properties of the specified device that can be used in udev rules to match the specified device]' \
10+
'--export[Print output as key/value pairs.]' \
11+
'--export-prefix=[Add a prefix to the key name of exported values.]:prefix' \
12+
'--device-id-of-file=[Print major/minor numbers of the underlying device, where the file lives on.]:files:_udevadm_mounts' \
13+
'--export-db[Export the content of the udev database.]' \
14+
'--cleanup-db[Cleanup the udev database.]'
15+
}
16+
17+
_udevadm_trigger(){
18+
_arguments \
19+
'--verbose[Print the list of devices which will be triggered.]' \
20+
'--dry-run[Do not actually trigger the event.]' \
21+
'--type=[Trigger a specific type of devices.]:types:(devices subsystems failed)' \
22+
'--action=[Type of event to be triggered.]:actions:(add change remove)' \
23+
'--subsystem-match=[Trigger events for devices which belong to a matching subsystem.]' \
24+
'--subsystem-nomatch=[Do not trigger events for devices which belong to a matching subsystem.]' \
25+
'--attr-match=attribute=[Trigger events for devices with a matching sysfs attribute.]' \
26+
'--attr-nomatch=attribute=[Do not trigger events for devices with a matching sysfs attribute.]' \
27+
'--property-match=[Trigger events for devices with a matching property value.]' \
28+
'--tag-match=property[Trigger events for devices with a matching tag.]' \
29+
'--sysname-match=[Trigger events for devices with a matching sys device name.]' \
30+
'--parent-match=[Trigger events for all children of a given device.]'
31+
}
32+
33+
_udevadm_settle(){
34+
_arguments \
35+
'--timeout=[Maximum number of seconds to wait for the event queue to become empty.]' \
36+
'--seq-start=[Wait only for events after the given sequence number.]' \
37+
'--seq-end=[Wait only for events before the given sequence number.]' \
38+
'--exit-if-exists=[Stop waiting if file exists.]:files:_files' \
39+
'--quiet[Do not print any output, like the remaining queue entries when reaching the timeout.]' \
40+
'--help[Print help text.]'
41+
}
42+
43+
_udevadm_control(){
44+
_arguments \
45+
'--exit[Signal and wait for systemd-udevd to exit.]' \
46+
'--log-priority=[Set the internal log level of systemd-udevd.]:priorities:(err info debug)' \
47+
'--stop-exec-queue[Signal systemd-udevd to stop executing new events. Incoming events will be queued.]' \
48+
'--start-exec-queue[Signal systemd-udevd to enable the execution of events.]' \
49+
'--reload[Signal systemd-udevd to reload the rules files and other databases like the kernel module index.]' \
50+
'--property=[Set a global property for all events.]' \
51+
'--children-max=[Set the maximum number of events.]' \
52+
'--timeout=[The maximum number of seconds to wait for a reply from systemd-udevd.]' \
53+
'--help[Print help text.]'
54+
}
55+
56+
_udevadm_monitor(){
57+
_arguments \
58+
'--kernel[Print the kernel uevents.]' \
59+
'--udev[Print the udev event after the rule processing.]' \
60+
'--property[Also print the properties of the event.]' \
61+
'--subsystem-match=[Filter events by subsystem/\[devtype\].]' \
62+
'--tag-match=[Filter events by property.]' \
63+
'--help[Print help text.]'
64+
}
65+
66+
_udevadm_test(){
67+
_arguments \
68+
'--action=[The action string.]:actions:(add change remove)' \
69+
'--subsystem=[The subsystem string.]' \
70+
'--help[Print help text.]' \
71+
'*::devpath:_files -P /sys/ -W /sys'
72+
}
73+
74+
_udevadm_test-builtin(){
75+
if (( CURRENT == 2 )); then
76+
_arguments \
77+
'--help[Print help text]' \
78+
'*::builtins:(blkid btrfs hwdb input_id kmod path_id usb_id uaccess)'
79+
elif (( CURRENT == 3 )); then
80+
_arguments \
81+
'--help[Print help text]' \
82+
'*::syspath:_files -P /sys -W /sys'
83+
else
84+
_arguments \
85+
'--help[Print help text]'
86+
fi
87+
}
88+
89+
_udevadm_mounts(){
90+
local dev_tmp dpath_tmp mp_tmp mline
91+
92+
tmp=( "${(@f)$(< /etc/mtab)}" )
93+
dev_tmp=( "${(@)${(@)tmp%% *}:#none}" )
94+
mp_tmp=( "${(@)${(@)tmp#* }%% *}" )
95+
96+
local MATCH
97+
mp_tmp=("${(@q)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}")
98+
dpath_tmp=( "${(@Mq)dev_tmp:#/*}" )
99+
dev_tmp=( "${(@q)dev_tmp:#/*}" )
100+
101+
_alternative \
102+
'device-paths: device path:compadd -a dpath_tmp' \
103+
'directories:mount point:compadd -a mp_tmp'
104+
}
105+
106+
107+
_udevadm_command(){
108+
local -a _udevadm_cmds
109+
_udevadm_cmds=(
110+
'info:query sysfs or the udev database'
111+
'trigger:request events from the kernel'
112+
'settle:wait for the event queue to finish'
113+
'control:control the udev daemon'
114+
'monitor:listen to kernel and udev events'
115+
'test:test an event run'
116+
'test-builtin:test a built-in command'
117+
)
118+
119+
if ((CURRENT == 1)); then
120+
_describe -t commands 'udevadm commands' _udevadm_cmds
121+
else
122+
local curcontext="$curcontext"
123+
cmd="${${_udevadm_cmds[(r)$words[1]:*]%%:*}}"
124+
if (($#cmd)); then
125+
if (( $+functions[_udevadm_$cmd] )); then
126+
_udevadm_$cmd
127+
else
128+
_message "no options for $cmd"
129+
fi
130+
else
131+
_message "no more options"
132+
fi
133+
fi
134+
}
135+
136+
137+
_arguments \
138+
'--debug[Print debug messages to stderr]' \
139+
'--version[Print version number]' \
140+
'--help[Print help text]' \
141+
'*::udevadm commands:_udevadm_command'

0 commit comments

Comments
 (0)