chiark / gitweb /
add Belarussian mapping: simple, 'by' and 'by'
[elogind.git] / shell-completion / systemd-zsh-completion.zsh
1 #compdef systemctl 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
2
3 _ctls()
4 {
5     local curcontext="$curcontext" state lstate line
6     case "$service" in
7         systemctl)
8             # -s for aggregated options like -aP
9             _arguments -s \
10                 {-h,--help}'[Show help]' \
11                 '--version[Show package version]' \
12                 {-t,--type=}'[List only units of a particular type]:unit type:(automount device mount path service snapshot socket swap target timer)' \
13                 \*{-p,--property=}'[Show only properties by specific name]:unit property' \
14                 {-a,--all}'[Show all units/properties, including dead/empty ones]' \
15                 '--failed[Show only failed units]' \
16                 "--full[Don't ellipsize unit names on output]" \
17                 '--fail[When queueing a new job, fail if conflicting jobs are pending]' \
18                 '--ignore-dependencies[When queueing a new job, ignore all its dependencies]' \
19                 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
20                 {-s,--signal=}'[Which signal to send]:signal:_signals' \
21                 {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
22                 {-P,--privileged}'[Acquire privileges before execution]' \
23                 {-q,--quiet}'[Suppress output]' \
24                 '--no-block[Do not wait until operation finished]' \
25                 "--no-wall[Don't send wall message before halt/power-off/reboot]" \
26                 "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \
27                 '--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \
28                 '--no-pager[Do not pipe output into a pager]' \
29                 '--no-ask-password[Do not ask for system passwords]' \
30                 '--order[When generating graph for dot, show only order]' \
31                 '--require[When generating graph for dot, show only requirement]' \
32                 '--system[Connect to system manager]' \
33                 '--user[Connect to user service manager]' \
34                 '--global[Enable/disable unit files globally]' \
35                 {-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \
36                 '--root=[Enable unit files in the specified root directory]:directory:_directories' \
37                 '--runtime[Enable unit files only temporarily until next reboot]' \
38                 {-n,--lines=}'[Journal entries to show]:number of entries' \
39                 {-o,--output=}'[Change journal output mode]:modes:_outputmodes' \
40                 '*::systemctl command:_systemctl_command'
41         ;;
42         loginctl)
43             _arguments -s \
44                 {-h,--help}'[Show help]' \
45                 '--version[Show package version]' \
46                 \*{-p,--property=}'[Show only properties by this name]:unit property' \
47                 {-a,--all}'[Show all properties, including empty ones]' \
48                 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
49                 {-s,--signal=}'[Which signal to send]:signal:_signals' \
50                 '--no-ask-password[Do not ask for system passwords]' \
51                 {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
52                 {-P,--privileged}'[Acquire privileges before execution]' \
53                 '--no-pager[Do not pipe output into a pager]' \
54                 '*::loginctl command:_loginctl_command'
55         ;;
56
57         hostnamectl)
58             _arguments -s \
59                 {-h,--help}'[Show this help]' \
60                 '--version[Show package version]' \
61                 '--transient[Only set transient hostname]' \
62                 '--static[Only set static hostname]' \
63                 '--pretty[Only set pretty hostname]' \
64                 '--no-ask-password[Do not prompt for password]' \
65                 {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
66                 '*::hostnamectl commands:_hostnamectl_command'
67         ;;
68         journalctl)
69             _arguments -s \
70                 '--since=[Start showing entries newer or of the specified date]:YYYY-MM-DD HH\:MM\:SS' \
71                 '--until=[Stop showing entries older or of the specified date]:YYYY-MM-DD HH\:MM\:SS' \
72                 {-c,--cursor=}'[Start showing entries from specified cursor]:cursors:_journal_fields __CURSORS' \
73                 {-b,--this-boot}'[Show data only from current boot]' \
74                 {-u,--unit=}'[Show data only from the specified unit]:units:_journal_fields _SYSTEMD_UNIT' \
75                 {-p,--priority=}'[Show only messages within the specified priority range]:priority:_journal_fields PRIORITY' \
76                 {-f,--follow}'[Follow journal]' \
77                 {-n,--lines=}'[Number of journal entries to show]:integer' \
78                 '--no-tail[Show all lines, even in follow mode]' \
79                 {-o,--output=}'[Change journal output mode]:output modes:_outputmodes' \
80                 '--full[Show long fields in full]' \
81                 {-a,--all}'[Show all fields, including long and unprintable]' \
82                 {-q,--quiet}"[Don't show privilege warning]" \
83                 '--no-pager[Do not pipe output into a pager]' \
84                 {-m,--merge}'[Show entries from all available journals]' \
85                 {-D,--directory=}'[Show journal files from directory]:directories:_directories' \
86                 '--interval=[Time interval for changing the FSS sealing key]:time interval' \
87                 '--verify-key=[Specify FSS verification key]:FSS key' \
88                 {-h,--help}'[Show this help]' \
89                 '--version[Show package version]' \
90                 '--new-id128[Generate a new 128 Bit ID]' \
91                 '--header[Show journal header information]' \
92                 '--disk-usage[Show total disk usage]' \
93                 {-F,--field=}'[List all values a certain field takes]:Fields:_list_fields' \
94                 '--setup-keys[Generate new FSS key pair]' \
95                 '--verify[Verify journal file consistency]' \
96                 '--list-catalog[List messages in catalog]' \
97                 '--update-catalog[Update binary catalog database]' \
98         ;;
99         localectl)
100             _arguments \
101                 {-h,--help}'[Show this help]' \
102                 '--version[Show package version]' \
103                 "--no-convert[Don't convert keyboard mappings]" \
104                 '--no-pager[Do not pipe output into a pager]' \
105                 '--no-ask-password[Do not prompt for password]' \
106                 {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
107                 '*::localectl commands:_localectl_command'
108         ;;
109         systemd-coredumpctl)
110             _arguments \
111                 {-o,--output=}'[Write output to FILE]:output file:_files' \
112                 '--no-pager[Do not pipe output into a pager]' \
113                 {-h,--help}'[Show this help]' \
114                 '--version[Show package version]' \
115                 '*::systemd-coredumpctl commands:_systemd-coredumpctl_command'
116
117         ;;
118         timedatectl)
119             _arguments -s \
120                 {-h,--help}'[Show this help]' \
121                 '--version[Show package version]' \
122                 '--adjust-system-clock[Adjust system clock when changing local RTC mode]' \
123                 '--no-pager[Do not pipe output into a pager]' \
124                 '--no-ask-password[Do not prompt for password]' \
125                 {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
126                 '*::timedatectl commands:_timedatectl_command'
127         ;;
128         udevadm)
129             _arguments \
130                 '--debug[Print debug messages to stderr]' \
131                 '--version[Print version number]' \
132                 '--help[Print help text]' \
133                 '*::udevadm commands:_udevadm_command'
134         ;;
135         systemd-analyze)
136             _arguments \
137                 {-h,--help}'[Show help text.]' \
138                 '--user[Shows performance data of user sessions instead of the system manager.]' \
139                 '*::systemd-analyze commands:_systemd_analyze_command'
140         ;;
141         systemd-ask-password)
142             _arguments \
143                 {-h,--help}'[Show this help]' \
144                 '--icon=[Icon name]' \
145                 '--timeout=[Timeout in sec]' \
146                 '--no-tty[Ask question via agent even on TTY]' \
147                 '--accept-cached[Accept cached passwords]' \
148                 '--multiple[List multiple passwords if available]'
149         ;;
150         systemd-cat)
151             _arguments \
152                 {-h,--help}'[Show this help]' \
153                 '--version[Show package version.]' \
154                 {-t,--identifier=}'[Set syslog identifier.]' \
155                 {-p,--priority=}'[Set priority value.]:value:({0..7})' \
156                 '--level-prefix=[Control whether level prefix shall be parsed.]:boolean:(1 0)' \
157                 ':Message'
158         ;;
159         systemd-cgls)
160             _arguments \
161                 {-h,--help}'[Show this help]' \
162                 '--version[Show package version]' \
163                 '--no-pager[Do not pipe output into a pager]' \
164                 {-a,--all}'[Show all groups, including empty]' \
165                 '-k[Include kernel threads in output]' \
166                 ':cgroups:(cpuset cpu cpuacct memory devices freezer net_cls blkio)'
167         ;;
168         systemd-cgtop)
169             _arguments \
170                 {-h,--help}'[Show this help]' \
171                 '--version[Print version and exit]' \
172                 '(-c -m -i -t)-p[Order by path]' \
173                 '(-c -p -m -i)-t[Order by number of tasks]' \
174                 '(-m -p -i -t)-c[Order by CPU load]' \
175                 '(-c -p -i -t)-m[Order by memory load]' \
176                 '(-c -m -p -t)-i[Order by IO load]' \
177                 {-d,--delay=}'[Specify delay]' \
178                 {-n,--iterations=}'[Run for N iterations before exiting]' \
179                 {-b,--batch}'[Run in batch mode, accepting no input]' \
180                 '--depth=[Maximum traversal depth]'
181         ;;
182         systemd-delta)
183             _arguments \
184                 {-h,--help}'[Show this help]' \
185                 '--version[Show package version]' \
186                 '--no-pager[Do not pipe output into a pager]' \
187                 '--diff=[Show a diff when overridden files differ]:boolean:(1 0)' \
188                 {-t,--type=}'[Only display a selected set of override types]:types:(masked equivalent redirected overridden unchanged)' \
189                 ':SUFFIX:(tmpfiles.d sysctl.d systemd/system)'
190         ;;
191         systemd-detect-virt)
192             _arguments \
193                 {-h,--help}'[Show this help]' \
194                 '--version[Show package version]' \
195                 {-c,--container}'[Only detect whether we are run in a container]' \
196                 {-v,--vm}'[Only detect whether we are run in a VM]' \
197                 {-q,--quiet}"[Don't output anything, just set return value]"
198         ;;
199         systemd-inhibit)
200             _arguments \
201                 {-h,--help}'[Show this help]' \
202                 '--version[Show package version]' \
203                 '--what=[Operations to inhibit]:options:(shutdown sleep idle handle-power-key handle-suspend-key handle-hibernate-key handle-lid-switch)' \
204                 '--who=[A descriptive string who is inhibiting]' \
205                 '--why=[A descriptive string why is being inhibited]' \
206                 '--mode=[One of block or delay]' \
207                 '--list[List active inhibitors]' \
208                 '*:commands:_systemd_inhibit_command'
209         ;;
210         systemd-machine-id-setup)
211             _arguments \
212                 {-h,--help}'[Show this help]' \
213                 '--version[Show package version]'
214         ;;
215         systemd-notify)
216             _arguments \
217                 {-h,--help}'[Show this help]' \
218                 '--version[Show package version]' \
219                 '--ready[Inform the init system about service start-up completion.]' \
220                 '--pid=[Inform the init system about the main PID of the daemon]' \
221                 '--status=[Send a free-form status string for the daemon to the init systemd]' \
222                 '--booted[Returns 0 if the system was booted up with systemd]' \
223                 '--readahead=[Controls disk read-ahead operations]:arguments:(cancel done noreply)'
224         ;;
225         systemd-nspawn)
226             _arguments \
227                 {-h,--help}'[Show this help]' \
228                 {--directory=,-D}'[Directory to use as file system root for the namespace container. If omitted the current directory will be used.]:directories:_directories' \
229                 {--boot,-b}'[Automatically search for an init binary and invoke it instead of a shell or a user supplied program.]' \
230                 {--user=,-u}'[Run the command under specified user, create home directory and cd into it.]' \
231                 '--uuid=[Set the specified uuid for the container.]' \
232                 {--controllers=,-C}'[Makes the container appear in other hierarchies than the name=systemd:/ one. Takes a comma-separated list of controllers.]' \
233                 '--private-network[Turn off networking in the container. This makes all network interfaces unavailable in the container, with the exception of the loopback device.]' \
234                 '--read-only[Mount the root file system read only for the container.]' \
235                 '--capability=[List one or more additional capabilities to grant the container.]:capabilities:_systemd-nspawn' \
236                 "--link-journal=[Control whether the container's journal shall be made visible to the host system.]:options:(no, host, guest, auto)" \
237                 '-j[Equivalent to --link-journal=guest.]'
238         ;;
239         systemd-tmpfiles)
240             _arguments \
241                 '--create[Create, set ownership/permissions based on the config files.]' \
242                 '--clean[Clean up all files and directories with an age parameter configured.]' \
243                 '--remove[All files and directories marked with r, R in the configuration files are removed.]' \
244                 '--prefix=[Only apply rules that apply to paths with the specified prefix.]' \
245                 '--help[Prints a short help text and exits.]' \
246                 '*::files:_files'
247         ;;
248         systemd-tty-ask-password-agent)
249             _arguments \
250                 {-h,--help}'[Prints a short help text and exits.]' \
251                 '--version[Prints a short version string and exits.]' \
252                 '--list[Lists all currently pending system password requests.]' \
253                 '--query[Process all currently pending system password requests by querying the user on the calling TTY.]' \
254                 '--watch[Continuously process password requests.]' \
255                 '--wall[Forward password requests to wall(1).]' \
256                 '--plymouth[Ask question with plymouth(8).]' \
257                 '--console[Ask question on /dev/console.]'
258         ;;
259         *) _message 'eh?' ;;
260     esac
261 }
262
263 _systemd-nspawn(){
264     local -a _caps
265     _caps=( CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH
266             CAP_FOWNER CAP_FSETID CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE
267             CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SETGID CAP_SETFCAP CAP_SETPCAP
268             CAP_SETUID CAP_SYS_ADMIN CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_TTY_CONFIG
269             CAP_SYS_RESOURCE CAP_SYS_BOOT )
270     _values -s , 'capabilities' "$_caps[@]"
271 }
272
273 _systemd_inhibit_command(){
274     if (( CURRENT == 1 )); then 
275         compset -q
276         _normal
277     else
278         local n=${words[(b:2:i)[^-]*]}
279         if (( n <= CURRENT )); then
280             compset -n $n
281             _alternative \
282                 'files:file:_files' \
283                 'commands:command:_normal' && return 0
284         fi
285         _default
286     fi
287
288 }
289
290 _systemd_analyze_command(){
291     local -a _systemd_analyze_cmds
292     _systemd_analyze_cmds=(
293         'time:Print the time taken to start'
294         'blame:prints a list of all running units, ordered by the time they took to initialize'
295         'plot:prints an SVG graphic detailing which system services have been started at what time'
296     )
297
298     if (( CURRENT == 1 )); then
299         _describe "options" _systemd_analyze_cmds
300     else
301         _message "no more options"
302     fi
303 }
304
305 _hosts_or_user_at_host()
306 {
307   _alternative \
308     'users-hosts:: _user_at_host' \
309     'hosts:: _hosts'
310 }
311
312 _outputmodes() {
313     local -a _output_opts
314     _output_opts=(short short-monotonic verbose export json json-pretty json-see cat)
315     _describe -t output 'output mode' _output_opts || compadd "$@"
316 }
317         
318
319 (( $+functions[_systemctl_command] )) || _systemctl_command()
320 {
321   local -a _systemctl_cmds
322   _systemctl_cmds=(
323     "list-units:List units"
324     "start:Start (activate) one or more units"
325     "stop:Stop (deactivate) one or more units"
326     "reload:Reload one or more units"
327     "restart:Start or restart one or more units"
328     "condrestart:Restart one or more units if active"
329     "try-restart:Restart one or more units if active"
330     "reload-or-restart:Reload one or more units if possible, otherwise start or restart"
331     "force-reload:Reload one or more units if possible, otherwise restart if active"
332     "hibernate:Hibernate the system"
333     "hybrid-sleep:Hibernate and suspend the system"
334     "reload-or-try-restart:Reload one or more units if possible, otherwise restart if active"
335     "isolate:Start one unit and stop all others"
336     "kill:Send signal to processes of a unit"
337     "is-active:Check whether units are active"
338     "status:Show runtime status of one or more units"
339     "show:Show properties of one or more units/jobs or the manager"
340     "reset-failed:Reset failed state for all, one, or more units"
341     "load:Load one or more units"
342     "list-unit-files:List installed unit files"
343     "enable:Enable one or more unit files"
344     "disable:Disable one or more unit files"
345     "reenable:Reenable one or more unit files"
346     "preset:Enable/disable one or more unit files based on preset configuration"
347     "mask:Mask one or more units"
348     "unmask:Unmask one or more units"
349     "link:Link one or more units files into the search path"
350     "is-enabled:Check whether unit files are enabled"
351     "list-jobs:List jobs"
352     "cancel:Cancel all, one, or more jobs"
353     "dump:Dump server status"
354     "dot:Dump dependency graph for dot(1)"
355     "snapshot:Create a snapshot"
356     "delete:Remove one or more snapshots"
357     "show-environment:Dump environment"
358     "set-environment:Set one or more environment variables"
359     "unset-environment:Unset one or more environment variables"
360     "daemon-reload:Reload systemd manager configuration"
361     "daemon-reexec:Reexecute systemd manager"
362     "default:Enter system default mode"
363     "rescue:Enter system rescue mode"
364     "emergency:Enter system emergency mode"
365     "halt:Shut down and halt the system"
366     "suspend:Suspend the system"
367     "poweroff:Shut down and power-off the system"
368     "reboot:Shut down and reboot the system"
369     "kexec:Shut down and reboot the system with kexec"
370     "exit:Ask for user instance termination"
371   )
372
373   if (( CURRENT == 1 )); then
374     _describe -t commands 'systemctl command' _systemctl_cmds || compadd "$@"
375   else
376     local curcontext="$curcontext"
377
378     cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}"
379     # Deal with any aliases
380     case $cmd in
381       condrestart) cmd="try-restart";;
382       force-reload) cmd="reload-or-try-restart";;
383     esac
384
385     if (( $#cmd )); then
386       curcontext="${curcontext%:*:*}:systemctl-${cmd}:"
387
388       local update_policy
389       zstyle -s ":completion:${curcontext}:" cache-policy update_policy
390       if [[ -z "$update_policy" ]]; then
391         zstyle ":completion:${curcontext}:" cache-policy _systemctl_caching_policy
392       fi
393
394       _call_function ret _systemctl_$cmd || _message 'no more arguments'
395     else
396       _message "unknown systemctl command: $words[1]"
397     fi
398     return ret
399   fi
400 }
401
402 __systemctl()
403 {
404   systemctl --full --no-legend --no-pager "$@"
405 }
406
407
408 # Fills the unit list
409 _systemctl_all_units()
410 {
411   if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
412     ! _retrieve_cache SYS_ALL_UNITS;
413   then
414     _sys_all_units=( $(__systemctl list-units --all | { while read a b; do echo "$a"; done; }) )
415     _store_cache SYS_ALL_UNITS _sys_all_units
416   fi
417 }
418
419 # Fills the unit list including all file units
420 _systemctl_really_all_units()
421 {
422   local -a all_unit_files;
423   local -a really_all_units;
424   if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
425     ! _retrieve_cache SYS_REALLY_ALL_UNITS;
426   then
427     all_unit_files=( $(__systemctl list-unit-files | { while read a b; do echo "$a"; done; }) )
428     _systemctl_all_units
429     really_all_units=($_sys_all_units $all_unit_files)
430     _sys_really_all_units=(${(u)really_all_units})
431     _store_cache SYS_REALLY_ALL_UNITS _sys_really_all_units
432   fi
433 }
434
435 _filter_units_by_property() {
436   local property=$1 value=$2 ; shift ; shift
437   local -a units ; units=($*)
438   local prop unit
439   for ((i=1; $i <= ${#units[*]}; i++)); do
440     # FIXME: "Failed to issue method call: Unknown unit" errors are ignored for
441     # now (related to DBUS_ERROR_UNKNOWN_OBJECT). in the future, we need to
442     # revert to calling 'systemctl show' once for all units, which is way
443     # faster
444     unit=${units[i]}
445     prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
446     if [[ "${prop}" = "$property=$value" ]]; then
447       echo "${unit}"
448     fi
449   done
450 }
451
452 _systemctl_active_units()  {_sys_active_units=(  $(__systemctl list-units          | { while read a b; do echo "$a"; done; }) )}
453 _systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all    | { while read a b c d; do [[ $c == "inactive" ]] && echo "$a"; done; }) )}
454 _systemctl_failed_units()  {_sys_failed_units=(  $(__systemctl list-units --failed | { while read a b; do echo "$a"; done; }) )}
455 _systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files     | { while read a b; do [[ $b == "enabled" ]] && echo "$a"; done; }) )}
456 _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files     | { while read a b; do [[ $b == "disabled" ]] && echo "$a"; done; }) )}
457 _systemctl_masked_units()  {_sys_masked_units=(  $(__systemctl list-unit-files     | { while read a b; do [[ $b == "masked" ]] && echo "$a"; done; }) )}
458
459 # Completion functions for ALL_UNITS
460 for fun in is-active is-enabled status show mask preset ; do
461   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
462   {
463     _systemctl_really_all_units
464     compadd "$@" -a - _sys_really_all_units
465   }
466 done
467
468 # Completion functions for ENABLED_UNITS
469 for fun in disable reenable ; do
470   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
471   {
472     _systemctl_enabled_units
473     compadd "$@" -a - _sys_enabled_units
474   }
475 done
476
477 # Completion functions for DISABLED_UNITS
478 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
479 {
480   _systemctl_disabled_units
481   compadd "$@" -a - _sys_disabled_units
482 }
483
484 # Completion functions for FAILED_UNITS
485 (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
486 {
487   _systemctl_failed_units
488   compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
489 }
490
491 # Completion functions for STARTABLE_UNITS
492 (( $+functions[_systemctl_start] )) || _systemctl_start()
493 {
494   _systemctl_inactive_units
495   compadd "$@" -a - _sys_inactive_units
496 }
497
498 # Completion functions for STOPPABLE_UNITS
499 for fun in stop kill try-restart condrestart ; do
500   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
501   {
502     _systemctl_active_units
503     compadd "$@" - $( _filter_units_by_property CanStop yes \
504       ${_sys_active_units[*]} )
505   }
506 done
507
508 # Completion functions for ISOLATABLE_UNITS
509 (( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
510 {
511   _systemctl_all_units
512   compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
513     ${_sys_all_units[*]} )
514 }
515
516 # Completion functions for RELOADABLE_UNITS
517 for fun in reload reload-or-try-restart force-reload ; do
518   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
519   {
520     _systemctl_active_units
521     compadd "$@" - $( _filter_units_by_property CanReload yes \
522       ${_sys_active_units[*]} )
523   }
524 done
525
526 # Completion functions for RESTARTABLE_UNITS
527 for fun in restart reload-or-restart ; do
528   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
529   {
530     _systemctl_all_units
531     compadd "$@" - $( _filter_units_by_property CanStart yes \
532       ${_sys_all_units[*]} | while read line; do \
533       [[ "$line" =~ \.(device|snapshot|socket|timer)$ ]] || echo "$line"; \
534       done )
535   }
536 done
537
538 # Completion functions for MASKED_UNITS
539 (( $+functions[_systemctl_unmask] )) || _systemctl_unmask()
540 {
541   _systemctl_masked_units
542   compadd "$@" -a - _sys_masked_units || _message "no masked unit found"
543 }
544
545 # Completion functions for JOBS
546 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
547 {
548   compadd "$@" - $(__systemctl list-jobs \
549     | cut -d' ' -f1  2>/dev/null ) || _message "no job found"
550 }
551
552 # Completion functions for SNAPSHOTS
553 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
554 {
555   compadd "$@" - $(__systemctl list-units --type snapshot --all \
556     | cut -d' ' -f1  2>/dev/null ) || _message "no snampshot found"
557 }
558
559 # Completion functions for ENVS
560 for fun in set-environment unset-environment ; do
561   (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
562   {
563     local fun=$0 ; fun=${fun##_systemctl_}
564     local suf
565     if [[ "${fun}" = "set-environment" ]]; then
566       suf='-S='
567     fi
568
569     compadd "$@" ${suf} - $(systemctl show-environment \
570       | while read line; do echo "${line%%\=}";done )
571   }
572 done
573
574 (( $+functions[_systemctl_link] )) || _systemctl_link() { _files }
575
576 # no systemctl completion for:
577 #    [STANDALONE]='daemon-reexec daemon-reload default dot dump
578 #                  emergency exit halt kexec list-jobs list-units
579 #                  list-unit-files poweroff reboot rescue show-environment'
580 #         [NAME]='snapshot load'
581
582 _systemctl_caching_policy()
583 {
584   local _sysunits
585   local -a oldcache
586
587   # rebuild if cache is more than a day old
588   oldcache=( "$1"(mh+1) )
589   (( $#oldcache )) && return 0
590
591   _sysunits=($(__systemctl --all | cut -d' ' -f1))
592
593   if (( $#_sysunits )); then
594     for unit in $_sysunits; do
595       [[ "$unit" -nt "$1" ]] && return 0
596     done
597   fi
598
599   return 1
600 }
601
602 _list_fields() {
603     local -a journal_fields
604     journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
605                     ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID}
606                     _{P,U,G}ID _COMM _EXE _CMDLINE
607                     _AUDIT_{SESSION,LOGINUID}
608                     _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
609                     _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
610                     _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
611                     _KERNEL_{DEVICE,SUBSYSTEM}
612                     _UDEV_{SYSNAME,DEVNODE,DEVLINK}
613                     __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
614     _describe 'possible fields' journal_fields
615 }
616
617 _journal_fields() {
618     local -a _fields cmd
619     cmd=("journalctl" "-F ${@[-1]}" "2>/dev/null" )
620     _fields=( ${(f)"$(_call_program fields $cmd[@])"} ) 
621     typeset -U _fields
622     _describe 'possible values' _fields
623 }
624
625
626 _loginctl_all_sessions(){_sys_all_sessions=($(loginctl list-sessions | { while read a b; do echo "$a"; done; }) )}
627 _loginctl_all_users()   {_sys_all_users=(   $(loginctl list-users    | { while read a b; do echo "$a"; done; }) )}
628 _loginctl_all_seats()   {_sys_all_seats=(   $(loginctl list-seats    | { while read a b; do echo "$a"; done; }) )}
629
630 # Completion functions for SESSIONS
631 for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
632   (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
633   {
634     _loginctl_all_sessions
635     compadd "$@" -a - _sys_all_sessions
636   }
637 done
638
639 # Completion functions for USERS
640 for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
641   (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
642   {
643     _loginctl_all_users
644     compadd "$@" -a - _sys_all_users
645   }
646 done
647
648 # Completion functions for SEATS
649 (( $+functions[_loginctl_seats] )) || _loginctl_seats()
650 {
651   _loginctl_all_seats
652   compadd "$@" -a - _sys_all_seats
653 }
654 for fun in seat-status show-seat terminate-seat ; do
655   (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
656   { _loginctl_seats }
657 done
658
659 # Completion functions for ATTACH
660 (( $+functions[_loginctl_attach] )) || _loginctl_attach()
661 {
662   _loginctl_all_seats
663
664   _arguments -w -C -S -s \
665     ':seat:_loginctl_seats' \
666     '*:device:_files'
667 }
668
669 # no loginctl completion for:
670 # [STANDALONE]='list-sessions list-users list-seats flush-devices'
671
672 (( $+functions[_loginctl_command] )) || _loginctl_command()
673 {
674   local -a _loginctl_cmds
675   _loginctl_cmds=(
676     "list-sessions:List sessions"
677     "session-status:Show session status"
678     "show-session:Show properties of one or more sessions"
679     "activate:Activate a session"
680     "lock-session:Screen lock one or more sessions"
681     "unlock-session:Screen unlock one or more sessions"
682     "terminate-session:Terminate one or more sessions"
683     "kill-session:Send signal to processes of a session"
684     "list-users:List users"
685     "user-status:Show user status"
686     "show-user:Show properties of one or more users"
687     "enable-linger:Enable linger state of one or more users"
688     "disable-linger:Disable linger state of one or more users"
689     "terminate-user:Terminate all sessions of one or more users"
690     "kill-user:Send signal to processes of a user"
691     "list-seats:List seats"
692     "seat-status:Show seat status"
693     "show-seat:Show properties of one or more seats"
694     "attach:Attach one or more devices to a seat"
695     "flush-devices:Flush all device associations"
696     "terminate-seat:Terminate all sessions on one or more seats"
697   )
698
699   if (( CURRENT == 1 )); then
700     _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
701   else
702     local curcontext="$curcontext"
703
704     cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
705
706     if (( $#cmd )); then
707       curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
708
709       _call_function ret _loginctl_$cmd || _message 'no more arguments'
710     else
711       _message "unknown loginctl command: $words[1]"
712     fi
713     return ret
714   fi
715 }
716
717 _hostnamectl_command() {
718     local -a _hostnamectl_cmds
719     _hostnamectl_cmds=(
720         "status:Show current hostname settings"
721         "set-hostname:Set system hostname"
722         "set-icon-name:Set icon name for host"
723     )
724     if (( CURRENT == 1 )); then
725         _describe -t commands 'hostnamectl commands' _hostnamectl_cmds || compadd "$@"
726     else
727         local curcontext="$curcontext"
728         cmd="${${_hostnamectl_cmds[(r)$words[1]:*]%%:*}}"
729         if (( $#cmd )); then
730             [[ $cmd == status ]] && msg="no options" || msg="options for $cmd"
731             _message "$msg"
732         else
733             _message "unknown hostnamectl command: $words[1]"
734         fi
735     fi
736 }
737
738 _localectl_set-locale() {
739     local -a _confs _locales
740     local expl suf
741     _locales=( ${(f)"$(_call_program locales "$service" list-locales)"} )
742     _confs=( ${${(f)"$(_call_program confs "locale 2>/dev/null")"}%\=*} )
743     if [[ -prefix 1 *\= ]]; then
744         local conf=${PREFIX%%\=*}
745         compset -P1 '*='
746         _wanted locales expl "locales configs" \
747             _combination localeconfs  confs=$conf locales "$@" -
748     else
749         compadd -S '='  $_confs
750     fi
751 }
752
753 _localectl_set-keymap() {
754     local -a _keymaps
755     _keymaps=( ${(f)"$(_call_program locales "$service" list-keymaps)"} )
756     if (( CURRENT <= 3 )); then
757         _describe keymaps _keymaps
758     else
759         _message "no more options"
760     fi
761 }
762
763 _localectl_set-x11-keymap() {
764     if (( $+commands[pkg-config] )); then
765         local -a _file _layout _model _variant _options
766         local _xorg_lst
767         _xorg_lst=${"$($commands[pkg-config] xkeyboard-config --variable=xkb_base)"}
768         _file=( ${(ps:\n\!:)"$(<$_xorg_lst/rules/xorg.lst)"} )
769         _layout=( ${${${(M)${(f)_file[1]}:#  *}#  }%% *} )
770         _model=( ${${${(M)${(f)_file[2]}:#  *}#  }%% *} )
771         _variant=( ${${${(M)${(f)_file[3]}:#  *}#  }%% *} )
772         _options=( ${${${(M)${(f)_file[4]}:#  *}#  }%% *} )
773         #_layout=( ${(f)"$( echo $_file[1] | awk '/^  / {print $1}' )"} )
774         #_model=( ${(f)"$(echo $_file[2] | awk '/^  / {print $1}')"} )
775         #_variant=( ${(f)"$(echo $_file[3] | awk '/^  / {print $1}')"} )
776         #_options=( ${(f)"$(echo ${_file[4]//:/\\:} | awk '/^  / {print $1}')"} )
777         
778         case $CURRENT in 
779             2) _describe layouts _layout ;;
780             3) _describe models _model;;
781             4) _describe variants _variant;;
782             5) _describe options _options;;
783             *) _message "no more options"
784         esac
785     fi
786 }
787
788
789 _localectl_command() {
790     local -a _localectl_cmds
791     _localectl_cmds=(
792         'status:Show current locale settings'
793         'set-locale:Set system locale'
794         'list-locales:Show known locales'
795         'set-keymap:Set virtual console keyboard mapping'
796         'list-keymaps:Show known virtual console keyboard mappings'
797         'set-x11-keymap:Set X11 keyboard mapping'
798     )
799     if (( CURRENT == 1 )); then
800         _describe -t commands 'localectl command' _localectl_cmds
801     else
802         local curcontext="$curcontext"
803         cmd="${${_localectl_cmds[(r)$words[1]:*]%%:*}}"
804         if (( $+functions[_localectl_$cmd] )); then
805             _localectl_$cmd
806         else
807             _message "no more options"
808         fi
809     fi
810 }
811
812 _timedatectl_set-timezone(){
813     local -a _timezones
814     _timezones=( ${(f)"$(_call_program timezones "${service}" list-timezones)"} )
815     compadd "$_timezones[@]"
816 }
817
818 _timedatectl_set-time(){
819     _message "YYYY-MM-DD HH:MM:SS"
820 }
821
822 _timedatectl_set-local-rtc(){
823     local -a _options
824     _options=(
825         '0:Maintain RTC in universal time'
826         '1:Maintain RTC in local time'
827     )
828     _describe options _options
829 }
830
831 _timedatectl_set-ntp(){
832     local -a _options
833     _options=(
834         '0:Disable NTP based network time configuration'
835         '1:Enable NTP based network time configuration'
836     )
837     _describe options _options
838 }
839
840 _timedatectl_command(){
841     local -a _timedatectl_cmds
842     _timedatectl_cmds=(
843         'status:Show current time settings'
844         'set-time:Set system time'
845         'set-timezone:Set system timezone'
846         'list-timezones:Show known timezones'
847         'set-local-rtc:Control whether RTC is in local time'
848         'set-ntp:Control whether NTP is enabled'
849     )
850     if (( CURRENT == 1 )); then
851         _describe -t commands 'timedatectl command' _timedatectl_cmds
852     else
853         local curcontext="$curcontext"
854         cmd="${${_timedatectl_cmds[(r)$words[1]:*]%%:*}}"
855         if (( $#cmd )); then
856             if (( $+functions[_timedatectl_$cmd] )); then
857                 _timedatectl_$cmd
858             else
859                 _message "no more options"
860             fi
861         else
862             _message "unknown timedatectl command: $words[1]"
863         fi
864     fi
865 }
866 _systemd-coredumpctl_command(){
867     local -a _systemd_coredumpctl_cmds
868     _systemd_coredumpctl_cmds=(
869             'list:List available coredumps'
870             'dump:Print coredump to std'
871     )
872     if (( CURRENT == 1 )); then
873         _describe -t commands 'systemd-coredumpctl command' _systemd_coredumpctl_cmds
874     else
875         local curcontext="$curcontext"
876         local -a dumps
877         cmd="${${_systemd_coredumpctl_cmds[(r)$words[1]:*]%%:*}}"
878         if (( $#cmd  )); then
879             dumps=( "${(f)$(_call_program dumps "systemd-coredumpctl list 2>/dev/null")}" )
880             if [[ -n "$dumps" ]]; then
881                 compadd "${dumps[@]}"
882             else
883                 _message "no coredumps"
884             fi
885         else
886             _message "no more options"
887         fi
888
889     fi
890
891 }
892
893 _udevadm_info(){
894     _arguments \
895         '--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)' \
896         '--path=[The devpath of the device to query.]:sys files:_files -P /sys/ -W /sys' \
897         '--name=[The name of the device node or a symlink to query]:device files:_files -P /dev/ -W /dev' \
898         '--root[Print absolute paths in name or symlink query.]' \
899         '--attribute-walk[Print all sysfs properties of the specified device that can be used in udev rules to match the specified device]' \
900         '--export[Print output as key/value pairs.]' \
901         '--export-prefix=[Add a prefix to the key name of exported values.]:prefix' \
902         '--device-id-of-file=[Print major/minor numbers of the underlying device, where the file lives on.]:files:_udevadm_mounts' \
903         '--export-db[Export the content of the udev database.]' \
904         '--cleanup-db[Cleanup the udev database.]'
905 }
906
907 _udevadm_trigger(){
908     _arguments \
909         '--verbose[Print the list of devices which will be triggered.]' \
910         '--dry-run[Do not actually trigger the event.]' \
911         '--type=[Trigger a specific type of devices.]:types:(devices subsystems failed)' \
912         '--action=[Type of event to be triggered.]:actions:(add change remove)' \
913         '--subsystem-match=[Trigger events for devices which belong to a matching subsystem.]' \
914         '--subsystem-nomatch=[Do not trigger events for devices which belong to a matching subsystem.]' \
915         '--attr-match=attribute=[Trigger events for devices with a matching sysfs attribute.]' \
916         '--attr-nomatch=attribute=[Do not trigger events for devices with a matching sysfs attribute.]' \
917         '--property-match=[Trigger events for devices with a matching property value.]' \
918         '--tag-match=property[Trigger events for devices with a matching tag.]' \
919         '--sysname-match=[Trigger events for devices with a matching sys device name.]' \
920         '--parent-match=[Trigger events for all children of a given device.]'
921 }
922
923 _udevadm_settle(){
924     _arguments \
925        '--timeout=[Maximum number of seconds to wait for the event queue to become empty.]' \
926        '--seq-start=[Wait only for events after the given sequence number.]' \
927        '--seq-end=[Wait only for events before the given sequence number.]' \
928        '--exit-if-exists=[Stop waiting if file exists.]:files:_files' \
929        '--quiet[Do not print any output, like the remaining queue entries when reaching the timeout.]' \
930        '--help[Print help text.]'
931 }
932
933 _udevadm_control(){
934     _arguments \
935         '--exit[Signal and wait for systemd-udevd to exit.]' \
936         '--log-priority=[Set the internal log level of systemd-udevd.]:priorities:(err info debug)' \
937         '--stop-exec-queue[Signal systemd-udevd to stop executing new events. Incoming events will be queued.]' \
938         '--start-exec-queue[Signal systemd-udevd to enable the execution of events.]' \
939         '--reload[Signal systemd-udevd to reload the rules files and other databases like the kernel module index.]' \
940         '--property=[Set a global property for all events.]' \
941         '--children-max=[Set the maximum number of events.]' \
942         '--timeout=[The maximum number of seconds to wait for a reply from systemd-udevd.]' \
943         '--help[Print help text.]'
944 }
945  
946 _udevadm_monitor(){
947     _arguments \
948         '--kernel[Print the kernel uevents.]' \
949         '--udev[Print the udev event after the rule processing.]' \
950         '--property[Also print the properties of the event.]' \
951         '--subsystem-match=[Filter events by subsystem[/devtype].]' \
952         '--tag-match=[Filter events by property.]' \
953         '--help[Print help text.]'
954 }
955
956 _udevadm_test(){
957     _arguments \
958         '--action=[The action string.]:actions:(add change remove)' \
959         '--subsystem=[The subsystem string.]' \
960         '--help[Print help text.]' \
961         '*::devpath:_files -P /sys/ -W /sys'
962 }
963
964 _udevadm_test-builtin(){
965     if (( CURRENT == 2 )); then
966     _arguments \
967         '--help[Print help text]' \
968         '*::builtins:(blkid btrfs firmware hwdb input_id kmod path_id usb_id uaccess)'
969     elif  (( CURRENT == 3 )); then
970         _arguments \
971             '--help[Print help text]' \
972             '*::syspath:_files -P /sys -W /sys'
973     else
974         _arguments \
975             '--help[Print help text]'
976     fi
977 }
978
979 _udevadm_mounts(){
980   local dev_tmp dpath_tmp mp_tmp mline
981
982     tmp=( "${(@f)$(< /etc/mtab)}" )
983     dev_tmp=( "${(@)${(@)tmp%% *}:#none}" )
984     mp_tmp=( "${(@)${(@)tmp#* }%% *}" )
985
986   local MATCH
987   mp_tmp=("${(@q)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}")
988   dpath_tmp=( "${(@Mq)dev_tmp:#/*}" )
989   dev_tmp=( "${(@q)dev_tmp:#/*}" )
990
991   _alternative \
992     'device-paths: device path:compadd -a dpath_tmp' \
993     'directories:mount point:compadd -a mp_tmp'
994 }
995
996
997 _udevadm_command(){
998     local -a _udevadm_cmds
999     _udevadm_cmds=(
1000         'info:query sysfs or the udev database'
1001         'trigger:request events from the kernel'
1002         'settle:wait for the event queue to finish'
1003         'control:control the udev daemon'
1004         'monitor:listen to kernel and udev events'
1005         'test:test an event run'
1006         'test-builtin:test a built-in command'
1007     )
1008
1009     if ((CURRENT == 1)); then
1010         _describe -t commands 'udevadm commands' _udevadm_cmds
1011     else
1012         local curcontext="$curcontext"
1013         cmd="${${_udevadm_cmds[(r)$words[1]:*]%%:*}}"
1014         if (($#cmd)); then
1015             if (( $+functions[_udevadm_$cmd] )); then
1016                 _udevadm_$cmd
1017             else
1018                 _message "no options for $cmd"
1019             fi
1020         else
1021             _message "no more options"
1022         fi
1023     fi
1024 }
1025
1026 _ctls "$@"
1027
1028 #vim: set ft=zsh sw=4 ts=4 et