chiark / gitweb /
shell-completion: systemd-analyze verify, systemctl link
[elogind.git] / shell-completion / zsh / _udevadm
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 net_id net_setup_link 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'