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