3 (( $+functions[_systemctl_command] )) || _systemctl_command()
5 local -a _systemctl_cmds
7 "list-sockets:List sockets"
8 "list-units:List units"
9 "start:Start (activate) one or more units"
10 "stop:Stop (deactivate) one or more units"
11 "reload:Reload one or more units"
12 "restart:Start or restart one or more units"
13 "condrestart:Restart one or more units if active"
14 "try-restart:Restart one or more units if active"
15 "reload-or-restart:Reload one or more units if possible, otherwise start or restart"
16 "force-reload:Reload one or more units if possible, otherwise restart if active"
17 "hibernate:Hibernate the system"
18 "hybrid-sleep:Hibernate and suspend the system"
19 "reload-or-try-restart:Reload one or more units if possible, otherwise restart if active"
20 "isolate:Start one unit and stop all others"
21 "kill:Send signal to processes of a unit"
22 "is-active:Check whether units are active"
23 "is-failed:Check whether units are failed"
24 "status:Show runtime status of one or more units"
25 "show:Show properties of one or more units/jobs or the manager"
26 "reset-failed:Reset failed state for all, one, or more units"
27 "load:Load one or more units"
28 "list-unit-files:List installed unit files"
29 "enable:Enable one or more unit files"
30 "disable:Disable one or more unit files"
31 "reenable:Reenable one or more unit files"
32 "preset:Enable/disable one or more unit files based on preset configuration"
33 "help:Show documentation for specified units"
34 "list-dependencies:Show unit dependency tree"
35 "mask:Mask one or more units"
36 "unmask:Unmask one or more units"
37 "link:Link one or more units files into the search path"
38 "is-enabled:Check whether unit files are enabled"
40 "cancel:Cancel all, one, or more jobs"
41 "dump:Dump server status"
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 a b; do echo " $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 a b; do echo " $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_active_units() {_sys_active_units=( $(__systemctl list-units | { while read a b; do echo " $a"; done; }) )}
142 _systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all | { while read a b c d; do [[ $c == "inactive" || $c == "failed" ]] && echo " $a"; done; }) )}
143 _systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read a b; do echo " $a"; done; }) )}
144 _systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "enabled" ]] && echo " $a"; done; }) )}
145 _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read a b; do [[ $b == "disabled" ]] && echo " $a"; done; }) )}
146 _systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "masked" ]] && echo " $a"; done; }) )}
148 # Completion functions for ALL_UNITS
149 for fun in is-active is-failed is-enabled status show mask preset help list-dependencies ; do
150 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
152 _systemctl_really_all_units
153 compadd "$@" -a - _sys_really_all_units
157 # Completion functions for ENABLED_UNITS
158 for fun in disable reenable ; do
159 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
161 _systemctl_enabled_units
162 _systemctl_disabled_units
163 compadd "$@" -a - _sys_enabled_units _sys_disabled_units
167 # Completion functions for DISABLED_UNITS
168 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
170 _systemctl_disabled_units
171 compadd "$@" -a - _sys_disabled_units
174 # Completion functions for FAILED_UNITS
175 (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
177 _systemctl_failed_units
178 compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
181 # Completion functions for STARTABLE_UNITS
182 (( $+functions[_systemctl_start] )) || _systemctl_start()
184 _systemctl_inactive_units
185 compadd "$@" -a - _sys_inactive_units
188 # Completion functions for STOPPABLE_UNITS
189 for fun in stop kill try-restart condrestart ; do
190 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
192 _systemctl_active_units
193 compadd "$@" - $( _filter_units_by_property CanStop yes \
194 ${_sys_active_units[*]} )
198 # Completion functions for ISOLATABLE_UNITS
199 (( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
202 compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
203 ${_sys_all_units[*]} )
206 # Completion functions for RELOADABLE_UNITS
207 for fun in reload reload-or-try-restart force-reload ; do
208 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
210 _systemctl_active_units
211 compadd "$@" - $( _filter_units_by_property CanReload yes \
212 ${_sys_active_units[*]} )
216 # Completion functions for RESTARTABLE_UNITS
217 for fun in restart reload-or-restart ; do
218 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
221 compadd "$@" - $( _filter_units_by_property CanStart yes \
222 ${_sys_all_units[*]} | while read line; do \
223 [[ "$line" =~ \.device$ ]] || echo " $line"; \
228 # Completion functions for MASKED_UNITS
229 (( $+functions[_systemctl_unmask] )) || _systemctl_unmask()
231 _systemctl_masked_units
232 compadd "$@" -a - _sys_masked_units || _message "no masked unit found"
235 # Completion functions for JOBS
236 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
238 compadd "$@" - $(__systemctl list-jobs \
239 | cut -d' ' -f1 2>/dev/null ) || _message "no job found"
242 # Completion functions for SNAPSHOTS
243 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
245 compadd "$@" - $(__systemctl list-units --type snapshot --all \
246 | cut -d' ' -f1 2>/dev/null ) || _message "no snapshot found"
249 # Completion functions for ENVS
250 for fun in set-environment unset-environment ; do
251 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
253 local fun=$0 ; fun=${fun##_systemctl_}
255 if [[ "${fun}" = "set-environment" ]]; then
259 compadd "$@" ${suf} - $(systemctl show-environment \
260 | while read line; do echo " ${line%%\=}";done )
264 (( $+functions[_systemctl_link] )) || _systemctl_link() { _files }
266 # no systemctl completion for:
267 # [STANDALONE]='daemon-reexec daemon-reload default dump
268 # emergency exit halt kexec list-jobs list-units
269 # list-unit-files poweroff reboot rescue show-environment'
270 # [NAME]='snapshot load'
272 _systemctl_caching_policy()
277 # rebuild if cache is more than a day old
278 oldcache=( "$1"(mh+1) )
279 (( $#oldcache )) && return 0
281 _sysunits=($(__systemctl --all | cut -d' ' -f1))
283 if (( $#_sysunits )); then
284 for unit in $_sysunits; do
285 [[ "$unit" -nt "$1" ]] && return 0
293 local -a _output_opts
294 _output_opts=(short short-monotonic verbose export json json-pretty json-see cat)
295 _describe -t output 'output mode' _output_opts || compadd "$@"
300 _states=(loaded failed active inactive not-found listening running waiting plugged mounted exited dead masked)
301 _values -s , "${_states[@]}"
306 _types=(automount device mount path service snapshot socket swap target timer)
307 _values -s , "${_types[@]}"
311 {-h,--help}'[Show help]' \
312 '--version[Show package version]' \
313 {-t+,--type=}'[List only units of a particular type]:unit type:_unit_types' \
314 '--state=[Display units in the specifyied state]:unit state:_unit_states' \
315 \*{-p+,--property=}'[Show only properties by specific name]:unit property' \
316 {-a,--all}'[Show all units/properties, including dead/empty ones]' \
317 '--reverse[Show reverse dependencies]' \
318 '--after[Show units ordered after]' \
319 '--before[Show units ordered before]' \
320 '--failed[Show only failed units]' \
321 {-l,--full}"[Don't ellipsize unit names on output]" \
322 '--fail[When queueing a new job, fail if conflicting jobs are pending]' \
323 '--show-types[When showing sockets, show socket type]' \
324 '--irreversible[Mark transactions as irreversible]' \
325 '--ignore-dependencies[When queueing a new job, ignore all its dependencies]' \
326 {-i,--ignore-inhibitors}'[When executing a job, ignore jobs dependencies]' \
327 {-q,--quiet}'[Suppress output]' \
328 '--no-block[Do not wait until operation finished]' \
329 '--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \
330 '--no-pager[Do not pipe output into a pager]' \
331 '--system[Connect to system manager]' \
332 '--user[Connect to user service manager]' \
333 "--no-wall[Don't send wall message before halt/power-off/reboot]" \
334 '--global[Enable/disable unit files globally]' \
335 "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \
336 '--no-ask-password[Do not ask for system passwords]' \
337 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
338 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
339 {-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \
340 '--root=[Enable unit files in the specified root directory]:directory:_directories' \
341 '--runtime[Enable unit files only temporarily until next reboot]' \
342 {-H+,--host=}'[Show information for remote host]:userathost:_sd_hosts_or_user_at_host' \
343 {-P,--privileged}'[Acquire privileges before execution]' \
344 {-n+,--lines=}'[Journal entries to show]:number of entries' \
345 {-o+,--output=}'[Change journal output mode]:modes:_outputmodes' \
346 '--plain[When used with list-dependencies, print output as a list]' \
347 '*::systemctl command:_systemctl_command'