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