3 (( $+functions[_systemctl_command] )) || _systemctl_command()
5 local -a _systemctl_cmds
7 "list-sockets:List sockets"
8 "list-timers:List timers"
9 "list-units:List units"
10 "start:Start (activate) one or more units"
11 "stop:Stop (deactivate) one or more units"
12 "reload:Reload one or more units"
13 "restart:Start or restart one or more units"
14 "condrestart:Restart one or more units if active"
15 "try-restart:Restart one or more units if active"
16 "reload-or-restart:Reload one or more units if possible, otherwise start or restart"
17 "force-reload:Reload one or more units if possible, otherwise restart if active"
18 "hibernate:Hibernate the system"
19 "hybrid-sleep:Hibernate and suspend the system"
20 "reload-or-try-restart:Reload one or more units if possible, otherwise restart if active"
21 "isolate:Start one unit and stop all others"
22 "kill:Send signal to processes of a unit"
23 "is-active:Check whether units are active"
24 "is-failed:Check whether units are failed"
25 "status:Show runtime status of one or more units"
26 "show:Show properties of one or more units/jobs or the manager"
27 "cat:Show the source unit files and drop-ins"
28 "reset-failed:Reset failed state for all, one, or more units"
29 "list-unit-files:List installed unit files"
30 "enable:Enable one or more unit files"
31 "disable:Disable one or more unit files"
32 "reenable:Reenable one or more unit files"
33 "preset:Enable/disable one or more unit files based on preset configuration"
34 "set-default:Set the default target"
35 "get-default:Query the default target"
36 "edit:Edit one or more unit files"
37 "is-system-running:Query overall status of the system"
38 "help:Show documentation for specified units"
39 "list-dependencies:Show unit dependency tree"
40 "mask:Mask one or more units"
41 "unmask:Unmask one or more units"
42 "link:Link one or more units files into the search path"
43 "is-enabled:Check whether unit files are enabled"
45 "cancel:Cancel all, one, or more jobs"
46 "snapshot:Create a snapshot"
47 "delete:Remove one or more snapshots"
48 "show-environment:Dump environment"
49 "set-environment:Set one or more environment variables"
50 "unset-environment:Unset one or more environment variables"
51 "daemon-reload:Reload systemd manager configuration"
52 "daemon-reexec:Reexecute systemd manager"
53 "default:Enter system default mode"
54 "rescue:Enter system rescue mode"
55 "emergency:Enter system emergency mode"
56 "halt:Shut down and halt the system"
57 "suspend:Suspend the system"
58 "poweroff:Shut down and power-off the system"
59 "reboot:Shut down and reboot the system"
60 "kexec:Shut down and reboot the system with kexec"
61 "exit:Ask for user instance termination"
64 if (( CURRENT == 1 )); then
65 _describe -t commands 'systemctl command' _systemctl_cmds || compadd "$@"
67 local curcontext="$curcontext"
69 cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}"
70 # Deal with any aliases
72 condrestart) cmd="try-restart";;
73 force-reload) cmd="reload-or-try-restart";;
77 curcontext="${curcontext%:*:*}:systemctl-${cmd}:"
80 zstyle -s ":completion:${curcontext}:" cache-policy update_policy
81 if [[ -z "$update_policy" ]]; then
82 zstyle ":completion:${curcontext}:" cache-policy _systemctl_caching_policy
85 _call_function ret _systemctl_$cmd || _message 'no more arguments'
87 _message "unknown systemctl command: $words[1]"
96 _modes=("--user" "--system")
97 systemctl ${words:*_modes} --full --no-legend --no-pager "$@"
101 # Fills the unit list
102 _systemctl_all_units()
104 if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
105 ! _retrieve_cache SYS_ALL_UNITS;
107 _sys_all_units=( $(__systemctl list-units --all | { while read -r a b; do echo -E - " $a"; done; }) )
108 _store_cache SYS_ALL_UNITS _sys_all_units
112 # Fills the unit list including all file units
113 _systemctl_really_all_units()
115 local -a all_unit_files;
116 local -a really_all_units;
117 if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
118 ! _retrieve_cache SYS_REALLY_ALL_UNITS;
120 all_unit_files=( $(__systemctl list-unit-files | { while read -r a b; do echo -E - " $a"; done; }) )
122 really_all_units=($_sys_all_units $all_unit_files)
123 _sys_really_all_units=(${(u)really_all_units})
124 _store_cache SYS_REALLY_ALL_UNITS _sys_really_all_units
128 _filter_units_by_property() {
129 local property=$1 value=$2 ; shift ; shift
130 local -a units ; units=($*)
132 for ((i=1; $i <= ${#units[*]}; i++)); do
133 # FIXME: "Failed to issue method call: Unknown unit" errors are ignored for
134 # now (related to DBUS_ERROR_UNKNOWN_OBJECT). in the future, we need to
135 # revert to calling 'systemctl show' once for all units, which is way
138 prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
139 if [[ "${prop}" = "$property=$value" ]]; then
145 _systemctl_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; } }
146 _systemctl_get_template_names() { __systemctl list-unit-files | { while read -r a b; do [[ $a =~ @\. ]] && echo -E - " ${a%%@.*}@"; done; } }
149 _systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read -r a b; do echo -E - " $a"; done; }) )}
151 _systemctl_startable_units(){
152 _sys_startable_units=(_filter_units_by_property ActiveState inactive $(
153 _filter_units_by_property CanStart yes $(
154 __systemctl $mode list-unit-files --state enabled,disabled,static | \
155 { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; }
156 __systemctl $mode list-units --state inactive,failed | \
157 { while read -r a b; do echo -E - " $a"; done; } )))
160 _systemctl_restartable_units(){
161 _sys_restartable_units=(_filter_units_by_property CanStart yes $(
162 __systemctl $mode list-unit-files --state enabled,disabled,static | \
163 { while read -r a b; do [[ $a =~ @\. ]] || echo -E - " $a"; done; }
164 __systemctl $mode list-units | \
165 { while read -r a b; do echo -E - " $a"; done; } ))
168 _systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read -r a b; do echo -E - " $a"; done; }) )}
169 _systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; }) )}
170 _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; }) )}
171 _systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == "masked" ]] && echo -E - " $a"; done; }) )}
173 # Completion functions for ALL_UNITS
174 for fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies edit ; do
175 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
177 _systemctl_really_all_units
178 compadd "$@" -a - _sys_really_all_units
182 # Completion functions for ENABLED_UNITS
183 (( $+functions[_systemctl_disable] )) || _systemctl_disable()
185 _systemctl_enabled_units
186 compadd "$@" -a - _sys_enabled_units
189 (( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
191 _systemctl_enabled_units
192 _systemctl_disabled_units
193 compadd "$@" -a - _sys_enabled_units _sys_disabled_units $(_systemctl_get_template_names)
196 # Completion functions for DISABLED_UNITS
197 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
199 _systemctl_disabled_units
200 compadd "$@" -a - _sys_disabled_units $(_systemctl_get_template_names)
203 # Completion functions for FAILED_UNITS
204 (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
206 _systemctl_failed_units
207 compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
210 # Completion functions for STARTABLE_UNITS
211 (( $+functions[_systemctl_start] )) || _systemctl_start()
213 _systemctl_startable_units
214 compadd "$@" - ${_sys_startable_units[*]} $(_systemctl_get_template_names)
217 # Completion functions for STOPPABLE_UNITS
218 for fun in stop kill try-restart condrestart ; do
219 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
221 _systemctl_active_units
222 compadd "$@" - $( _filter_units_by_property CanStop yes \
223 ${_sys_active_units[*]} )
227 # Completion functions for ISOLATABLE_UNITS
228 (( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
231 compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
232 ${_sys_all_units[*]} )
235 # Completion functions for RELOADABLE_UNITS
236 for fun in reload reload-or-try-restart force-reload ; do
237 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
239 _systemctl_active_units
240 compadd "$@" - $( _filter_units_by_property CanReload yes \
241 ${_sys_active_units[*]} )
245 # Completion functions for RESTARTABLE_UNITS
246 for fun in restart reload-or-restart ; do
247 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
249 _systemctl_restartable_units
250 compadd "$@" - ${_sys_restartable_units[*]} $(_systemctl_get_template_names)
254 # Completion functions for MASKED_UNITS
255 (( $+functions[_systemctl_unmask] )) || _systemctl_unmask()
257 _systemctl_masked_units
258 compadd "$@" -a - _sys_masked_units || _message "no masked units found"
261 # Completion functions for JOBS
262 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
264 compadd "$@" - $(__systemctl list-jobs \
265 | cut -d' ' -f1 2>/dev/null ) || _message "no jobs found"
268 # Completion functions for SNAPSHOTS
269 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
271 compadd "$@" - $(__systemctl list-units --type snapshot --all \
272 | cut -d' ' -f1 2>/dev/null ) || _message "no snapshots found"
275 # Completion functions for TARGETS
276 (( $+functions[_systemctl_set-default] )) || _systemctl_set-default()
278 compadd "$@" - $(__systemctl list-unit-files --type target --all \
279 | cut -d' ' -f1 2>/dev/null ) || _message "no targets found"
282 # Completion functions for ENVS
283 for fun in set-environment unset-environment ; do
284 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
286 local fun=$0 ; fun=${fun##_systemctl_}
288 if [[ "${fun}" = "set-environment" ]]; then
292 compadd "$@" ${suf} - $(systemctl show-environment \
293 | while read line; do echo " ${line%%\=}";done )
297 (( $+functions[_systemctl_link] )) || _systemctl_link() {
301 # no systemctl completion for:
302 # [STANDALONE]='daemon-reexec daemon-reload default
303 # emergency exit halt kexec list-jobs list-units
304 # list-unit-files poweroff reboot rescue show-environment'
307 _systemctl_caching_policy()
312 # rebuild if cache is more than a day old
313 oldcache=( "$1"(mh+1) )
314 (( $#oldcache )) && return 0
316 _sysunits=($(__systemctl --all | cut -d' ' -f1))
318 if (( $#_sysunits )); then
319 for unit in $_sysunits; do
320 [[ "$unit" -nt "$1" ]] && return 0
329 _states=(loaded failed active inactive not-found listening running waiting plugged mounted exited dead masked)
330 _values -s , "${_states[@]}"
335 _types=(automount busname device mount path service snapshot socket swap target timer)
336 _values -s , "${_types[@]}"
340 if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid SYS_ALL_PROPERTIES ) &&
341 ! _retrieve_cache SYS_ALL_PROPERTIES;
343 _sys_all_properties=( $( {__systemctl show --all;
344 @rootlibexecdir@/systemd --dump-configuration-items; } | {
345 while IFS='=' read -r a b; do [ -n "$b" ] && echo "$a"; done
347 _store_cache SYS_ALL_PROPRTIES _sys_all_properties
349 _values -s , "${_sys_all_properties[@]}"
353 {-h,--help}'[Show help]' \
354 '--version[Show package version]' \
355 {-t+,--type=}'[List only units of a particular type]:unit type:_unit_types' \
356 '--state=[Display units in the specifyied state]:unit state:_unit_states' \
357 {-p+,--property=}'[Show only properties by specific name]:unit property:_unit_properties' \
358 {-a,--all}'[Show all units/properties, including dead/empty ones]' \
359 '--reverse[Show reverse dependencies]' \
360 '--after[Show units ordered after]' \
361 '--before[Show units ordered before]' \
362 '--failed[Show only failed units]' \
363 {-l,--full}"[Don't ellipsize unit names on output]" \
364 '--fail[When queueing a new job, fail if conflicting jobs are pending]' \
365 '--show-types[When showing sockets, show socket type]' \
366 '--irreversible[Mark transactions as irreversible]' \
367 '--ignore-dependencies[When queueing a new job, ignore all its dependencies]' \
368 {-i,--ignore-inhibitors}'[When executing a job, ignore jobs dependencies]' \
369 {-q,--quiet}'[Suppress output]' \
370 '--no-block[Do not wait until operation finished]' \
371 '--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \
372 '--no-pager[Do not pipe output into a pager]' \
373 '--system[Connect to system manager]' \
374 '--user[Connect to user service manager]' \
375 "--no-wall[Don't send wall message before halt/power-off/reboot]" \
376 '--global[Enable/disable unit files globally]' \
377 "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \
378 '--no-ask-password[Do not ask for system passwords]' \
379 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
380 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
381 {-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \
382 '--root=[Enable unit files in the specified root directory]:directory:_directories' \
383 '--runtime[Enable unit files only temporarily until next reboot]' \
384 {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
385 {-P,--privileged}'[Acquire privileges before execution]' \
386 {-n+,--lines=}'[Journal entries to show]:number of entries' \
387 {-o+,--output=}'[Change journal output mode]:modes:_sd_outputmodes' \
388 '--plain[When used with list-dependencies, print output as a list]' \
389 '*::systemctl command:_systemctl_command'