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 "help:Show documentation for specified units"
35 "list-dependencies:Show unit dependency tree"
36 "mask:Mask one or more units"
37 "unmask:Unmask one or more units"
38 "link:Link one or more units files into the search path"
39 "is-enabled:Check whether unit files are enabled"
41 "cancel:Cancel all, one, or more jobs"
42 "snapshot:Create a snapshot"
43 "delete:Remove one or more snapshots"
44 "show-environment:Dump environment"
45 "set-environment:Set one or more environment variables"
46 "unset-environment:Unset one or more environment variables"
47 "daemon-reload:Reload systemd manager configuration"
48 "daemon-reexec:Reexecute systemd manager"
49 "default:Enter system default mode"
50 "rescue:Enter system rescue mode"
51 "emergency:Enter system emergency mode"
52 "halt:Shut down and halt the system"
53 "suspend:Suspend the system"
54 "poweroff:Shut down and power-off the system"
55 "reboot:Shut down and reboot the system"
56 "kexec:Shut down and reboot the system with kexec"
57 "exit:Ask for user instance termination"
60 if (( CURRENT == 1 )); then
61 _describe -t commands 'systemctl command' _systemctl_cmds || compadd "$@"
63 local curcontext="$curcontext"
65 cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}"
66 # Deal with any aliases
68 condrestart) cmd="try-restart";;
69 force-reload) cmd="reload-or-try-restart";;
73 curcontext="${curcontext%:*:*}:systemctl-${cmd}:"
76 zstyle -s ":completion:${curcontext}:" cache-policy update_policy
77 if [[ -z "$update_policy" ]]; then
78 zstyle ":completion:${curcontext}:" cache-policy _systemctl_caching_policy
81 _call_function ret _systemctl_$cmd || _message 'no more arguments'
83 _message "unknown systemctl command: $words[1]"
92 _modes=("--user" "--system")
93 systemctl ${words:*_modes} --full --no-legend --no-pager "$@"
98 _systemctl_all_units()
100 if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
101 ! _retrieve_cache SYS_ALL_UNITS;
103 _sys_all_units=( $(__systemctl list-units --all | { while read -r a b; do echo -E - " $a"; done; }) )
104 _store_cache SYS_ALL_UNITS _sys_all_units
108 # Fills the unit list including all file units
109 _systemctl_really_all_units()
111 local -a all_unit_files;
112 local -a really_all_units;
113 if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
114 ! _retrieve_cache SYS_REALLY_ALL_UNITS;
116 all_unit_files=( $(__systemctl list-unit-files | { while read -r a b; do echo -E - " $a"; done; }) )
118 really_all_units=($_sys_all_units $all_unit_files)
119 _sys_really_all_units=(${(u)really_all_units})
120 _store_cache SYS_REALLY_ALL_UNITS _sys_really_all_units
124 _filter_units_by_property() {
125 local property=$1 value=$2 ; shift ; shift
126 local -a units ; units=($*)
128 for ((i=1; $i <= ${#units[*]}; i++)); do
129 # FIXME: "Failed to issue method call: Unknown unit" errors are ignored for
130 # now (related to DBUS_ERROR_UNKNOWN_OBJECT). in the future, we need to
131 # revert to calling 'systemctl show' once for all units, which is way
134 prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
135 if [[ "${prop}" = "$property=$value" ]]; then
141 _systemctl_all_units() { { __systemctl list-unit-files; __systemctl list-units --all; } | { while read -r a b; do echo -E - " $a"; done; } }
142 _systemctl_get_template_names() { __systemctl list-unit-files | { while read -r a b; do [[ $a =~ @\. ]] && echo -E - " ${a%%@.*}@"; done; } }
145 _systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read -r a b; do echo -E - " $a"; done; }) )}
146 _systemctl_startable_units(){_sys_startable_units=($(__systemctl list-units --state inactive,failed -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )}
147 _systemctl_restartable_units(){_sys_restartable_units=($(__systemctl list-units --state inactive,failed,active -- $(_systemctl_all_units) | { while read -r a b c d; do [[ $b == "loaded" ]] && echo -E - " $a"; done; }) )}
148 _systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read -r a b; do echo -E - " $a"; done; }) )}
149 _systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == "enabled" ]] && echo -E - " $a"; done; }) )}
150 _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read -r a b; do [[ $b == "disabled" ]] && echo -E - " $a"; done; }) )}
151 _systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == "masked" ]] && echo -E - " $a"; done; }) )}
153 # Completion functions for ALL_UNITS
154 for fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies ; do
155 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
157 _systemctl_really_all_units
158 compadd "$@" -a - _sys_really_all_units
162 # Completion functions for ENABLED_UNITS
163 (( $+functions[_systemctl_disable] )) || _systemctl_disable()
165 _systemctl_enabled_units
166 compadd "$@" -a - _sys_enabled_units
169 (( $+functions[_systemctl_reenable] )) || _systemctl_reenable()
171 _systemctl_enabled_units
172 _systemctl_disabled_units
173 compadd "$@" -a - _sys_enabled_units _sys_disabled_units $(_systemctl_get_template_names)
176 # Completion functions for DISABLED_UNITS
177 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
179 _systemctl_disabled_units
180 compadd "$@" -a - _sys_disabled_units $(_systemctl_get_template_names)
183 # Completion functions for FAILED_UNITS
184 (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
186 _systemctl_failed_units
187 compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
190 # Completion functions for STARTABLE_UNITS
191 (( $+functions[_systemctl_start] )) || _systemctl_start()
193 _systemctl_startable_units
194 compadd "$@" - $( _filter_units_by_property CanStart yes \
195 ${_sys_startable_units[*]} )
198 # Completion functions for STOPPABLE_UNITS
199 for fun in stop kill try-restart condrestart ; do
200 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
202 _systemctl_active_units
203 compadd "$@" - $( _filter_units_by_property CanStop yes \
204 ${_sys_active_units[*]} )
208 # Completion functions for ISOLATABLE_UNITS
209 (( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
212 compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
213 ${_sys_all_units[*]} )
216 # Completion functions for RELOADABLE_UNITS
217 for fun in reload reload-or-try-restart force-reload ; do
218 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
220 _systemctl_active_units
221 compadd "$@" - $( _filter_units_by_property CanReload yes \
222 ${_sys_active_units[*]} )
226 # Completion functions for RESTARTABLE_UNITS
227 for fun in restart reload-or-restart ; do
228 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
230 _systemctl_restartable_units
231 compadd "$@" - $( _filter_units_by_property CanStart yes \
232 ${_sys_restartable_units[*]} )
236 # Completion functions for MASKED_UNITS
237 (( $+functions[_systemctl_unmask] )) || _systemctl_unmask()
239 _systemctl_masked_units
240 compadd "$@" -a - _sys_masked_units || _message "no masked unit found"
243 # Completion functions for JOBS
244 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
246 compadd "$@" - $(__systemctl list-jobs \
247 | cut -d' ' -f1 2>/dev/null ) || _message "no job found"
250 # Completion functions for SNAPSHOTS
251 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
253 compadd "$@" - $(__systemctl list-units --type snapshot --all \
254 | cut -d' ' -f1 2>/dev/null ) || _message "no snapshot found"
257 # Completion functions for ENVS
258 for fun in set-environment unset-environment ; do
259 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
261 local fun=$0 ; fun=${fun##_systemctl_}
263 if [[ "${fun}" = "set-environment" ]]; then
267 compadd "$@" ${suf} - $(systemctl show-environment \
268 | while read line; do echo " ${line%%\=}";done )
272 (( $+functions[_systemctl_link] )) || _systemctl_link() {
276 # no systemctl completion for:
277 # [STANDALONE]='daemon-reexec daemon-reload default
278 # emergency exit halt kexec list-jobs list-units
279 # list-unit-files poweroff reboot rescue show-environment'
282 _systemctl_caching_policy()
287 # rebuild if cache is more than a day old
288 oldcache=( "$1"(mh+1) )
289 (( $#oldcache )) && return 0
291 _sysunits=($(__systemctl --all | cut -d' ' -f1))
293 if (( $#_sysunits )); then
294 for unit in $_sysunits; do
295 [[ "$unit" -nt "$1" ]] && return 0
304 _states=(loaded failed active inactive not-found listening running waiting plugged mounted exited dead masked)
305 _values -s , "${_states[@]}"
310 _types=(automount busname device mount path service snapshot socket swap target timer)
311 _values -s , "${_types[@]}"
315 if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid SYS_ALL_PROPERTIES ) &&
316 ! _retrieve_cache SYS_ALL_PROPERTIES;
318 _sys_all_properties=( $( {__systemctl show --all;
319 @rootlibexecdir@/systemd --dump-configuration-items; } | {
320 while IFS='=' read -r a b; do [ -n "$b" ] && echo "$a"; done
322 _store_cache SYS_ALL_PROPRTIES _sys_all_properties
324 _values -s , "${_sys_all_properties[@]}"
328 {-h,--help}'[Show help]' \
329 '--version[Show package version]' \
330 {-t+,--type=}'[List only units of a particular type]:unit type:_unit_types' \
331 '--state=[Display units in the specifyied state]:unit state:_unit_states' \
332 {-p+,--property=}'[Show only properties by specific name]:unit property:_unit_properties' \
333 {-a,--all}'[Show all units/properties, including dead/empty ones]' \
334 '--reverse[Show reverse dependencies]' \
335 '--after[Show units ordered after]' \
336 '--before[Show units ordered before]' \
337 '--failed[Show only failed units]' \
338 {-l,--full}"[Don't ellipsize unit names on output]" \
339 '--fail[When queueing a new job, fail if conflicting jobs are pending]' \
340 '--show-types[When showing sockets, show socket type]' \
341 '--irreversible[Mark transactions as irreversible]' \
342 '--ignore-dependencies[When queueing a new job, ignore all its dependencies]' \
343 {-i,--ignore-inhibitors}'[When executing a job, ignore jobs dependencies]' \
344 {-q,--quiet}'[Suppress output]' \
345 '--no-block[Do not wait until operation finished]' \
346 '--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \
347 '--no-pager[Do not pipe output into a pager]' \
348 '--system[Connect to system manager]' \
349 '--user[Connect to user service manager]' \
350 "--no-wall[Don't send wall message before halt/power-off/reboot]" \
351 '--global[Enable/disable unit files globally]' \
352 "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \
353 '--no-ask-password[Do not ask for system passwords]' \
354 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
355 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
356 {-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \
357 '--root=[Enable unit files in the specified root directory]:directory:_directories' \
358 '--runtime[Enable unit files only temporarily until next reboot]' \
359 {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
360 {-P,--privileged}'[Acquire privileges before execution]' \
361 {-n+,--lines=}'[Journal entries to show]:number of entries' \
362 {-o+,--output=}'[Change journal output mode]:modes:_sd_outputmodes' \
363 '--plain[When used with list-dependencies, print output as a list]' \
364 '*::systemctl command:_systemctl_command'