chiark / gitweb /
80a14acb9976c6e2f88ab4d3558e3407d4b6a74e
[elogind.git] / shell-completion / zsh / _systemd
1 #compdef journalctl hostnamectl localectl timedatectl systemd-coredumpctl 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
2
3 _ctls()
4 {
5     local curcontext="$curcontext" state lstate line
6     case "$service" in
7         hostnamectl)
8             _arguments -s \
9                 {-h,--help}'[Show this help]' \
10                 '--version[Show package version]' \
11                 '--transient[Only set transient hostname]' \
12                 '--static[Only set static hostname]' \
13                 '--pretty[Only set pretty hostname]' \
14                 '--no-ask-password[Do not prompt for password]' \
15                 {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
16                 '*::hostnamectl commands:_hostnamectl_command'
17         ;;
18         journalctl)
19             _arguments -s \
20                 '--since=[Start showing entries newer or of the specified date]:YYYY-MM-DD HH\:MM\:SS' \
21                 '--until=[Stop showing entries older or of the specified date]:YYYY-MM-DD HH\:MM\:SS' \
22                 {-c,--cursor=}'[Start showing entries from specified cursor]:cursors:_journal_fields __CURSORS' \
23                 '--system[Show system and kernel messages]' \
24                 '--user[Show messages from user services]' \
25                 {-b,--this-boot}'[Show data only from current boot]' \
26                 {-u,--unit=}'[Show data only from the specified unit]:units:_journal_fields _SYSTEMD_UNIT' \
27                 '--user-unit[Show data only from the specified user session unit]:units:_journal_fields _SYSTEMD_USER_UNIT' \
28                 {-p,--priority=}'[Show only messages within the specified priority range]:priority:_journal_fields PRIORITY' \
29                 {-f,--follow}'[Follow journal]' \
30                 {-n,--lines=}'[Number of journal entries to show]:integer' \
31                 '--no-tail[Show all lines, even in follow mode]' \
32                 {-o,--output=}'[Change journal output mode]:output modes:_outputmodes' \
33                 {-l,--full}'[Show long fields in full]' \
34                 {-a,--all}'[Show all fields, including long and unprintable]' \
35                 {-q,--quiet}"[Don't show privilege warning]" \
36                 '--no-pager[Do not pipe output into a pager]' \
37                 {-m,--merge}'[Show entries from all available journals]' \
38                 {-D,--directory=}'[Show journal files from directory]:directories:_directories' \
39                 '--interval=[Time interval for changing the FSS sealing key]:time interval' \
40                 '--verify-key=[Specify FSS verification key]:FSS key' \
41                 {-h,--help}'[Show this help]' \
42                 '--version[Show package version]' \
43                 '--new-id128[Generate a new 128 Bit ID]' \
44                 '--header[Show journal header information]' \
45                 '--disk-usage[Show total disk usage]' \
46                 {-F,--field=}'[List all values a certain field takes]:Fields:_list_fields' \
47                 '--setup-keys[Generate new FSS key pair]' \
48                 '--verify[Verify journal file consistency]' \
49                 '--list-catalog[List messages in catalog]' \
50                 '--update-catalog[Update binary catalog database]' \
51                 '*::default: _journal_none'
52         ;;
53         localectl)
54             _arguments \
55                 {-h,--help}'[Show this help]' \
56                 '--version[Show package version]' \
57                 "--no-convert[Don't convert keyboard mappings]" \
58                 '--no-pager[Do not pipe output into a pager]' \
59                 '--no-ask-password[Do not prompt for password]' \
60                 {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
61                 '*::localectl commands:_localectl_command'
62         ;;
63         systemd-coredumpctl)
64             _arguments \
65                 {-o,--output=}'[Write output to FILE]:output file:_files' \
66                 '--no-pager[Do not pipe output into a pager]' \
67                 {-h,--help}'[Show this help]' \
68                 '--version[Show package version]' \
69                 '*::systemd-coredumpctl commands:_systemd-coredumpctl_command'
70
71         ;;
72         timedatectl)
73             _arguments -s \
74                 {-h,--help}'[Show this help]' \
75                 '--version[Show package version]' \
76                 '--adjust-system-clock[Adjust system clock when changing local RTC mode]' \
77                 '--no-pager[Do not pipe output into a pager]' \
78                 '--no-ask-password[Do not prompt for password]' \
79                 {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
80                 '*::timedatectl commands:_timedatectl_command'
81         ;;
82         udevadm)
83             _arguments \
84                 '--debug[Print debug messages to stderr]' \
85                 '--version[Print version number]' \
86                 '--help[Print help text]' \
87                 '*::udevadm commands:_udevadm_command'
88         ;;
89         systemd-analyze)
90             _arguments \
91                 {-h,--help}'[Show help text.]' \
92                 '--user[Shows performance data of user sessions instead of the system manager.]' \
93                 '--order[When generating graph for dot, show only order]' \
94                 '--require[When generating graph for dot, show only requirement]' \
95                 '*::systemd-analyze commands:_systemd_analyze_command'
96         ;;
97         systemd-ask-password)
98             _arguments \
99                 {-h,--help}'[Show this help]' \
100                 '--icon=[Icon name]' \
101                 '--timeout=[Timeout in sec]' \
102                 '--no-tty[Ask question via agent even on TTY]' \
103                 '--accept-cached[Accept cached passwords]' \
104                 '--multiple[List multiple passwords if available]'
105         ;;
106         systemd-cat)
107             _arguments \
108                 {-h,--help}'[Show this help]' \
109                 '--version[Show package version.]' \
110                 {-t,--identifier=}'[Set syslog identifier.]' \
111                 {-p,--priority=}'[Set priority value.]:value:({0..7})' \
112                 '--level-prefix=[Control whether level prefix shall be parsed.]:boolean:(1 0)' \
113                 ':Message'
114         ;;
115         systemd-cgls)
116             _arguments \
117                 {-h,--help}'[Show this help]' \
118                 '--version[Show package version]' \
119                 '--no-pager[Do not pipe output into a pager]' \
120                 {-a,--all}'[Show all groups, including empty]' \
121                 '-k[Include kernel threads in output]' \
122                 ':cgroups:(cpuset cpu cpuacct memory devices freezer net_cls blkio)'
123         ;;
124         systemd-cgtop)
125             _arguments \
126                 {-h,--help}'[Show this help]' \
127                 '--version[Print version and exit]' \
128                 '(-c -m -i -t)-p[Order by path]' \
129                 '(-c -p -m -i)-t[Order by number of tasks]' \
130                 '(-m -p -i -t)-c[Order by CPU load]' \
131                 '(-c -p -i -t)-m[Order by memory load]' \
132                 '(-c -m -p -t)-i[Order by IO load]' \
133                 {-d,--delay=}'[Specify delay]' \
134                 {-n,--iterations=}'[Run for N iterations before exiting]' \
135                 {-b,--batch}'[Run in batch mode, accepting no input]' \
136                 '--depth=[Maximum traversal depth]'
137         ;;
138         systemd-delta)
139             _arguments \
140                 {-h,--help}'[Show this help]' \
141                 '--version[Show package version]' \
142                 '--no-pager[Do not pipe output into a pager]' \
143                 '--diff=[Show a diff when overridden files differ]:boolean:(1 0)' \
144                 {-t,--type=}'[Only display a selected set of override types]:types:(masked equivalent redirected overridden unchanged)' \
145                 ':SUFFIX:(tmpfiles.d sysctl.d systemd/system)'
146         ;;
147         systemd-detect-virt)
148             _arguments \
149                 {-h,--help}'[Show this help]' \
150                 '--version[Show package version]' \
151                 {-c,--container}'[Only detect whether we are run in a container]' \
152                 {-v,--vm}'[Only detect whether we are run in a VM]' \
153                 {-q,--quiet}"[Don't output anything, just set return value]"
154         ;;
155         systemd-inhibit)
156             _arguments \
157                 {-h,--help}'[Show this help]' \
158                 '--version[Show package version]' \
159                 '--what=[Operations to inhibit]:options:(shutdown sleep idle handle-power-key handle-suspend-key handle-hibernate-key handle-lid-switch)' \
160                 '--who=[A descriptive string who is inhibiting]' \
161                 '--why=[A descriptive string why is being inhibited]' \
162                 '--mode=[One of block or delay]' \
163                 '--list[List active inhibitors]' \
164                 '*:commands:_systemd_inhibit_command'
165         ;;
166         systemd-machine-id-setup)
167             _arguments \
168                 {-h,--help}'[Show this help]' \
169                 '--version[Show package version]'
170         ;;
171         systemd-notify)
172             _arguments \
173                 {-h,--help}'[Show this help]' \
174                 '--version[Show package version]' \
175                 '--ready[Inform the init system about service start-up completion.]' \
176                 '--pid=[Inform the init system about the main PID of the daemon]' \
177                 '--status=[Send a free-form status string for the daemon to the init systemd]' \
178                 '--booted[Returns 0 if the system was booted up with systemd]' \
179                 '--readahead=[Controls disk read-ahead operations]:arguments:(cancel done noreply)'
180         ;;
181         systemd-nspawn)
182             _arguments \
183                 {-h,--help}'[Show this help]' \
184                 {--directory=,-D}'[Directory to use as file system root for the namespace container. If omitted the current directory will be used.]:directories:_directories' \
185                 {--boot,-b}'[Automatically search for an init binary and invoke it instead of a shell or a user supplied program.]' \
186                 {--user=,-u}'[Run the command under specified user, create home directory and cd into it.]' \
187                 '--uuid=[Set the specified uuid for the container.]' \
188                 {--controllers=,-C}'[Makes the container appear in other hierarchies than the name=systemd:/ one. Takes a comma-separated list of controllers.]' \
189                 '--private-network[Turn off networking in the container. This makes all network interfaces unavailable in the container, with the exception of the loopback device.]' \
190                 '--read-only[Mount the root file system read only for the container.]' \
191                 '--capability=[List one or more additional capabilities to grant the container.]:capabilities:_systemd-nspawn' \
192                 "--link-journal=[Control whether the container's journal shall be made visible to the host system.]:options:(no, host, guest, auto)" \
193                 '-j[Equivalent to --link-journal=guest.]'
194         ;;
195         systemd-tmpfiles)
196             _arguments \
197                 '--create[Create, set ownership/permissions based on the config files.]' \
198                 '--clean[Clean up all files and directories with an age parameter configured.]' \
199                 '--remove[All files and directories marked with r, R in the configuration files are removed.]' \
200                 '--prefix=[Only apply rules that apply to paths with the specified prefix.]' \
201                 '--exclude-prefix=[Ignore rules that apply to paths with the specified prefix.]' \
202                 '--help[Prints a short help text and exits.]' \
203                 '*::files:_files'
204         ;;
205         systemd-tty-ask-password-agent)
206             _arguments \
207                 {-h,--help}'[Prints a short help text and exits.]' \
208                 '--version[Prints a short version string and exits.]' \
209                 '--list[Lists all currently pending system password requests.]' \
210                 '--query[Process all currently pending system password requests by querying the user on the calling TTY.]' \
211                 '--watch[Continuously process password requests.]' \
212                 '--wall[Forward password requests to wall(1).]' \
213                 '--plymouth[Ask question with plymouth(8).]' \
214                 '--console[Ask question on /dev/console.]'
215         ;;
216         machinectl)
217             _arguments \
218                 {-h,--help}'[Prints a short help text and exits.]' \
219                 '--version[Prints a short version string and exits.]' \
220                 {-p,--property=}'[Limit output to specified property.]:property:(Name Id Timestamp TimestampMonotonic Service Scope Leader Class State RootDirectory)' \
221                 {-a,--all}'[Show all proerties]' \
222                 (-l,--full)'[Do not ellipsize cgroup members]' \
223                 '--no-pager[Do not pipe output into a pager]' \
224                 '--no-ask-password[Do not ask for system passwords]' \
225                 '--kill-who=[Who to send signal to]:killwho:(leader all)' \
226                 {-s,--signal=}'[Which signal to send]:signal:_signals' \
227                 {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
228                 {-P,--privileged}'[Acquire privileges before execution]' \
229                 '*::machinectl command:_machinectl_command'
230         ;;
231         *) _message 'eh?' ;;
232     esac
233 }
234
235 _systemd-nspawn(){
236     local -a _caps
237     _caps=( CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH
238             CAP_FOWNER CAP_FSETID CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE
239             CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SETGID CAP_SETFCAP CAP_SETPCAP
240             CAP_SETUID CAP_SYS_ADMIN CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_TTY_CONFIG
241             CAP_SYS_RESOURCE CAP_SYS_BOOT )
242     _values -s , 'capabilities' "$_caps[@]"
243 }
244
245 _systemd_inhibit_command(){
246     if (( CURRENT == 1 )); then
247         compset -q
248         _normal
249     else
250         local n=${words[(b:2:i)[^-]*]}
251         if (( n <= CURRENT )); then
252             compset -n $n
253             _alternative \
254                 'files:file:_files' \
255                 'commands:command:_normal' && return 0
256         fi
257         _default
258     fi
259
260 }
261
262 _systemd_analyze_command(){
263     local -a _systemd_analyze_cmds
264     # Descriptions taken from systemd-analyze --help.
265     _systemd_analyze_cmds=(
266         'time:Print time spent in the kernel before reaching userspace'
267         'blame:Print list of running units ordered by time to init'
268         'critical-chain:Print a tree of the time critical chain of units'
269         'plot:Output SVG graphic showing service initialization'
270         'dot:Dump dependency graph (in dot(1) format)'
271     )
272
273     if (( CURRENT == 1 )); then
274         _describe "options" _systemd_analyze_cmds
275     else
276         _message "no more options"
277     fi
278 }
279
280 _hosts_or_user_at_host()
281 {
282   _alternative \
283     'users-hosts:: _user_at_host' \
284     'hosts:: _hosts'
285 }
286
287 _outputmodes() {
288     local -a _output_opts
289     _output_opts=(short short-monotonic verbose export json json-pretty json-see cat)
290     _describe -t output 'output mode' _output_opts || compadd "$@"
291 }
292
293 _list_fields() {
294     local -a journal_fields
295     journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
296                     ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID}
297                     _{P,U,G}ID _COMM _EXE _CMDLINE
298                     _AUDIT_{SESSION,LOGINUID}
299                     _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
300                     _SYSTEMD_USER_UNIT
301                     _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
302                     _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
303                     _KERNEL_{DEVICE,SUBSYSTEM}
304                     _UDEV_{SYSNAME,DEVNODE,DEVLINK}
305                     __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
306     _describe 'possible fields' journal_fields
307 }
308
309 _journal_none() {
310     local -a _commands _files
311     _commands=( ${(f)"$(_call_program commands "$service" -F _EXE 2>/dev/null)"} )
312     _alternative : \
313         'files:/dev files:_files -W /dev -P /dev/' \
314         "commands:commands:($_commands[@])" \
315         'fields:fields:_list_fields'
316 }
317
318 _journal_fields() {
319     local -a _fields cmd
320     cmd=("journalctl" "-F ${@[-1]}" "2>/dev/null" )
321     _fields=( ${(f)"$(_call_program fields $cmd[@])"} )
322     typeset -U _fields
323     _describe 'possible values' _fields
324 }
325
326 _hostnamectl_command() {
327     local -a _hostnamectl_cmds
328     _hostnamectl_cmds=(
329         "status:Show current hostname settings"
330         "set-hostname:Set system hostname"
331         "set-icon-name:Set icon name for host"
332     )
333     if (( CURRENT == 1 )); then
334         _describe -t commands 'hostnamectl commands' _hostnamectl_cmds || compadd "$@"
335     else
336         local curcontext="$curcontext"
337         cmd="${${_hostnamectl_cmds[(r)$words[1]:*]%%:*}}"
338         if (( $#cmd )); then
339             [[ $cmd == status ]] && msg="no options" || msg="options for $cmd"
340             _message "$msg"
341         else
342             _message "unknown hostnamectl command: $words[1]"
343         fi
344     fi
345 }
346
347 _localectl_set-locale() {
348     local -a _confs _locales
349     local expl suf
350     _locales=( ${(f)"$(_call_program locales "$service" list-locales)"} )
351     _confs=( ${${(f)"$(_call_program confs "locale 2>/dev/null")"}%\=*} )
352     if [[ -prefix 1 *\= ]]; then
353         local conf=${PREFIX%%\=*}
354         compset -P1 '*='
355         _wanted locales expl "locales configs" \
356             _combination localeconfs  confs=$conf locales "$@" -
357     else
358         compadd -S '='  $_confs
359     fi
360 }
361
362 _localectl_set-keymap() {
363     local -a _keymaps
364     _keymaps=( ${(f)"$(_call_program locales "$service" list-keymaps)"} )
365     if (( CURRENT <= 3 )); then
366         _describe keymaps _keymaps
367     else
368         _message "no more options"
369     fi
370 }
371
372 _localectl_set-x11-keymap() {
373     if (( $+commands[pkg-config] )); then
374         local -a _file _layout _model _variant _options
375         local _xorg_lst
376         _xorg_lst=${"$($commands[pkg-config] xkeyboard-config --variable=xkb_base)"}
377         _file=( ${(ps:\n\!:)"$(<$_xorg_lst/rules/xorg.lst)"} )
378         _layout=( ${${${(M)${(f)_file[1]}:#  *}#  }%% *} )
379         _model=( ${${${(M)${(f)_file[2]}:#  *}#  }%% *} )
380         _variant=( ${${${(M)${(f)_file[3]}:#  *}#  }%% *} )
381         _options=( ${${${(M)${(f)_file[4]}:#  *}#  }%% *} )
382         #_layout=( ${(f)"$( echo $_file[1] | awk '/^  / {print $1}' )"} )
383         #_model=( ${(f)"$(echo $_file[2] | awk '/^  / {print $1}')"} )
384         #_variant=( ${(f)"$(echo $_file[3] | awk '/^  / {print $1}')"} )
385         #_options=( ${(f)"$(echo ${_file[4]//:/\\:} | awk '/^  / {print $1}')"} )
386
387         case $CURRENT in
388             2) _describe layouts _layout ;;
389             3) _describe models _model;;
390             4) _describe variants _variant;;
391             5) _describe options _options;;
392             *) _message "no more options"
393         esac
394     fi
395 }
396
397
398 _localectl_command() {
399     local -a _localectl_cmds
400     _localectl_cmds=(
401         'status:Show current locale settings'
402         'set-locale:Set system locale'
403         'list-locales:Show known locales'
404         'set-keymap:Set virtual console keyboard mapping'
405         'list-keymaps:Show known virtual console keyboard mappings'
406         'set-x11-keymap:Set X11 keyboard mapping'
407     )
408     if (( CURRENT == 1 )); then
409         _describe -t commands 'localectl command' _localectl_cmds
410     else
411         local curcontext="$curcontext"
412         cmd="${${_localectl_cmds[(r)$words[1]:*]%%:*}}"
413         if (( $+functions[_localectl_$cmd] )); then
414             _localectl_$cmd
415         else
416             _message "no more options"
417         fi
418     fi
419 }
420
421 _timedatectl_set-timezone(){
422     local -a _timezones
423     _timezones=( ${(f)"$(_call_program timezones "${service}" list-timezones)"} )
424     compadd "$_timezones[@]"
425 }
426
427 _timedatectl_set-time(){
428     _message "YYYY-MM-DD HH:MM:SS"
429 }
430
431 _timedatectl_set-local-rtc(){
432     local -a _options
433     _options=(
434         '0:Maintain RTC in universal time'
435         '1:Maintain RTC in local time'
436     )
437     _describe options _options
438 }
439
440 _timedatectl_set-ntp(){
441     local -a _options
442     _options=(
443         '0:Disable NTP based network time configuration'
444         '1:Enable NTP based network time configuration'
445     )
446     _describe options _options
447 }
448
449 _timedatectl_command(){
450     local -a _timedatectl_cmds
451     _timedatectl_cmds=(
452         'status:Show current time settings'
453         'set-time:Set system time'
454         'set-timezone:Set system timezone'
455         'list-timezones:Show known timezones'
456         'set-local-rtc:Control whether RTC is in local time'
457         'set-ntp:Control whether NTP is enabled'
458     )
459     if (( CURRENT == 1 )); then
460         _describe -t commands 'timedatectl command' _timedatectl_cmds
461     else
462         local curcontext="$curcontext"
463         cmd="${${_timedatectl_cmds[(r)$words[1]:*]%%:*}}"
464         if (( $#cmd )); then
465             if (( $+functions[_timedatectl_$cmd] )); then
466                 _timedatectl_$cmd
467             else
468                 _message "no more options"
469             fi
470         else
471             _message "unknown timedatectl command: $words[1]"
472         fi
473     fi
474 }
475 _systemd-coredumpctl_command(){
476     local -a _systemd_coredumpctl_cmds
477     _systemd_coredumpctl_cmds=(
478             'list:List available coredumps'
479             'dump:Print coredump to std'
480     )
481     if (( CURRENT == 1 )); then
482         _describe -t commands 'systemd-coredumpctl command' _systemd_coredumpctl_cmds
483     else
484         local curcontext="$curcontext"
485         local -a _dumps
486         cmd="${${_systemd_coredumpctl_cmds[(r)$words[1]:*]%%:*}}"
487         if (( $#cmd  )); then
488                         # user can set zstyle ':completion:*:*:systemd-coredumpctl:*' sort no for coredumps to be ordered by date, otherwise they get ordered by pid
489                         _dumps=( "${(foa)$(systemd-coredumpctl list | awk 'BEGIN{OFS=":"} /^\s/ {sub(/[[ \t]+/, ""); print $5,$0}' 2>/dev/null)}" )
490             if [[ -n "$_dumps" ]]; then
491                 _describe -t pids 'coredumps' _dumps
492             else
493                 _message "no coredumps"
494             fi
495         else
496             _message "no more options"
497         fi
498
499     fi
500
501 }
502
503 (( $+functions[_machinectl_command] )) || _machinectl_command()
504 {
505   local -a _machinectl_cmds
506   _machinectl_cmds=(
507     "list:List currently running VMs/containers"
508     "status:Show VM/container status"
509     "show:Show properties of one or more VMs/containers"
510     "terminate:Terminate one or more VMs/containers"
511     "kill:Send signal to process or a VM/container"
512   )
513   if (( CURRENT == 1 )); then
514     _describe -t commands 'machinectl command' _machinectl_cmds || compadd "$@"
515   else
516     local curcontext="$curcontext"
517     cmd="${${_machinectl_cmds[(r)$words[1]:*]%%:*}}"
518     if (( $#cmd )); then
519       case $cmd in
520         list) msg="no options" ;;
521         *)
522           _machines=( "${(foa)$(machinectl list | awk '{print $1}')}" )
523           if [[ -n "$_machines" ]]; then
524             _describe 'machines' _machines
525           else
526             _message 'no machines'
527           fi
528       esac
529     else
530       _message "no more options"
531     fi
532   fi
533 }
534
535 _udevadm_info(){
536     _arguments \
537         '--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)' \
538         '--path=[The devpath of the device to query.]:sys files:_files -P /sys/ -W /sys' \
539         '--name=[The name of the device node or a symlink to query]:device files:_files -P /dev/ -W /dev' \
540         '--root[Print absolute paths in name or symlink query.]' \
541         '--attribute-walk[Print all sysfs properties of the specified device that can be used in udev rules to match the specified device]' \
542         '--export[Print output as key/value pairs.]' \
543         '--export-prefix=[Add a prefix to the key name of exported values.]:prefix' \
544         '--device-id-of-file=[Print major/minor numbers of the underlying device, where the file lives on.]:files:_udevadm_mounts' \
545         '--export-db[Export the content of the udev database.]' \
546         '--cleanup-db[Cleanup the udev database.]'
547 }
548
549 _udevadm_trigger(){
550     _arguments \
551         '--verbose[Print the list of devices which will be triggered.]' \
552         '--dry-run[Do not actually trigger the event.]' \
553         '--type=[Trigger a specific type of devices.]:types:(devices subsystems failed)' \
554         '--action=[Type of event to be triggered.]:actions:(add change remove)' \
555         '--subsystem-match=[Trigger events for devices which belong to a matching subsystem.]' \
556         '--subsystem-nomatch=[Do not trigger events for devices which belong to a matching subsystem.]' \
557         '--attr-match=attribute=[Trigger events for devices with a matching sysfs attribute.]' \
558         '--attr-nomatch=attribute=[Do not trigger events for devices with a matching sysfs attribute.]' \
559         '--property-match=[Trigger events for devices with a matching property value.]' \
560         '--tag-match=property[Trigger events for devices with a matching tag.]' \
561         '--sysname-match=[Trigger events for devices with a matching sys device name.]' \
562         '--parent-match=[Trigger events for all children of a given device.]'
563 }
564
565 _udevadm_settle(){
566     _arguments \
567        '--timeout=[Maximum number of seconds to wait for the event queue to become empty.]' \
568        '--seq-start=[Wait only for events after the given sequence number.]' \
569        '--seq-end=[Wait only for events before the given sequence number.]' \
570        '--exit-if-exists=[Stop waiting if file exists.]:files:_files' \
571        '--quiet[Do not print any output, like the remaining queue entries when reaching the timeout.]' \
572        '--help[Print help text.]'
573 }
574
575 _udevadm_control(){
576     _arguments \
577         '--exit[Signal and wait for systemd-udevd to exit.]' \
578         '--log-priority=[Set the internal log level of systemd-udevd.]:priorities:(err info debug)' \
579         '--stop-exec-queue[Signal systemd-udevd to stop executing new events. Incoming events will be queued.]' \
580         '--start-exec-queue[Signal systemd-udevd to enable the execution of events.]' \
581         '--reload[Signal systemd-udevd to reload the rules files and other databases like the kernel module index.]' \
582         '--property=[Set a global property for all events.]' \
583         '--children-max=[Set the maximum number of events.]' \
584         '--timeout=[The maximum number of seconds to wait for a reply from systemd-udevd.]' \
585         '--help[Print help text.]'
586 }
587
588 _udevadm_monitor(){
589     _arguments \
590         '--kernel[Print the kernel uevents.]' \
591         '--udev[Print the udev event after the rule processing.]' \
592         '--property[Also print the properties of the event.]' \
593         '--subsystem-match=[Filter events by subsystem/\[devtype\].]' \
594         '--tag-match=[Filter events by property.]' \
595         '--help[Print help text.]'
596 }
597
598 _udevadm_test(){
599     _arguments \
600         '--action=[The action string.]:actions:(add change remove)' \
601         '--subsystem=[The subsystem string.]' \
602         '--help[Print help text.]' \
603         '*::devpath:_files -P /sys/ -W /sys'
604 }
605
606 _udevadm_test-builtin(){
607     if (( CURRENT == 2 )); then
608     _arguments \
609         '--help[Print help text]' \
610         '*::builtins:(blkid btrfs hwdb input_id kmod path_id usb_id uaccess)'
611     elif  (( CURRENT == 3 )); then
612         _arguments \
613             '--help[Print help text]' \
614             '*::syspath:_files -P /sys -W /sys'
615     else
616         _arguments \
617             '--help[Print help text]'
618     fi
619 }
620
621 _udevadm_mounts(){
622   local dev_tmp dpath_tmp mp_tmp mline
623
624     tmp=( "${(@f)$(< /etc/mtab)}" )
625     dev_tmp=( "${(@)${(@)tmp%% *}:#none}" )
626     mp_tmp=( "${(@)${(@)tmp#* }%% *}" )
627
628   local MATCH
629   mp_tmp=("${(@q)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}")
630   dpath_tmp=( "${(@Mq)dev_tmp:#/*}" )
631   dev_tmp=( "${(@q)dev_tmp:#/*}" )
632
633   _alternative \
634     'device-paths: device path:compadd -a dpath_tmp' \
635     'directories:mount point:compadd -a mp_tmp'
636 }
637
638
639 _udevadm_command(){
640     local -a _udevadm_cmds
641     _udevadm_cmds=(
642         'info:query sysfs or the udev database'
643         'trigger:request events from the kernel'
644         'settle:wait for the event queue to finish'
645         'control:control the udev daemon'
646         'monitor:listen to kernel and udev events'
647         'test:test an event run'
648         'test-builtin:test a built-in command'
649     )
650
651     if ((CURRENT == 1)); then
652         _describe -t commands 'udevadm commands' _udevadm_cmds
653     else
654         local curcontext="$curcontext"
655         cmd="${${_udevadm_cmds[(r)$words[1]:*]%%:*}}"
656         if (($#cmd)); then
657             if (( $+functions[_udevadm_$cmd] )); then
658                 _udevadm_$cmd
659             else
660                 _message "no options for $cmd"
661             fi
662         else
663             _message "no more options"
664         fi
665     fi
666 }
667
668 _ctls "$@"
669
670 #vim: set ft=zsh sw=4 ts=4 et