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 "snapshot:Create a snapshot"
42 "delete:Remove one or more snapshots"
43 "show-environment:Dump environment"
44 "set-environment:Set one or more environment variables"
45 "unset-environment:Unset one or more environment variables"
46 "daemon-reload:Reload systemd manager configuration"
47 "daemon-reexec:Reexecute systemd manager"
48 "default:Enter system default mode"
49 "rescue:Enter system rescue mode"
50 "emergency:Enter system emergency mode"
51 "halt:Shut down and halt the system"
52 "suspend:Suspend the system"
53 "poweroff:Shut down and power-off the system"
54 "reboot:Shut down and reboot the system"
55 "kexec:Shut down and reboot the system with kexec"
56 "exit:Ask for user instance termination"
59 if (( CURRENT == 1 )); then
60 _describe -t commands 'systemctl command' _systemctl_cmds || compadd "$@"
62 local curcontext="$curcontext"
64 cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}"
65 # Deal with any aliases
67 condrestart) cmd="try-restart";;
68 force-reload) cmd="reload-or-try-restart";;
72 curcontext="${curcontext%:*:*}:systemctl-${cmd}:"
75 zstyle -s ":completion:${curcontext}:" cache-policy update_policy
76 if [[ -z "$update_policy" ]]; then
77 zstyle ":completion:${curcontext}:" cache-policy _systemctl_caching_policy
80 _call_function ret _systemctl_$cmd || _message 'no more arguments'
82 _message "unknown systemctl command: $words[1]"
91 _modes=("--user" "--system")
92 systemctl ${words:*_modes} --full --no-legend --no-pager "$@"
97 _systemctl_all_units()
99 if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
100 ! _retrieve_cache SYS_ALL_UNITS;
102 _sys_all_units=( $(__systemctl list-units --all | { while read a b; do echo " $a"; done; }) )
103 _store_cache SYS_ALL_UNITS _sys_all_units
107 # Fills the unit list including all file units
108 _systemctl_really_all_units()
110 local -a all_unit_files;
111 local -a really_all_units;
112 if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
113 ! _retrieve_cache SYS_REALLY_ALL_UNITS;
115 all_unit_files=( $(__systemctl list-unit-files | { while read a b; do echo " $a"; done; }) )
117 really_all_units=($_sys_all_units $all_unit_files)
118 _sys_really_all_units=(${(u)really_all_units})
119 _store_cache SYS_REALLY_ALL_UNITS _sys_really_all_units
123 _filter_units_by_property() {
124 local property=$1 value=$2 ; shift ; shift
125 local -a units ; units=($*)
127 for ((i=1; $i <= ${#units[*]}; i++)); do
128 # FIXME: "Failed to issue method call: Unknown unit" errors are ignored for
129 # now (related to DBUS_ERROR_UNKNOWN_OBJECT). in the future, we need to
130 # revert to calling 'systemctl show' once for all units, which is way
133 prop=${(f)"$(_call_program units "$service show --no-pager --property="$property" ${unit} 2>/dev/null")"}
134 if [[ "${prop}" = "$property=$value" ]]; then
140 _systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read a b; do echo " $a"; done; }) )}
141 _systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all | { while read a b c d; do [[ $c == "inactive" || $c == "failed" ]] && echo " $a"; done; }) )}
142 _systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read a b; do echo " $a"; done; }) )}
143 _systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "enabled" ]] && echo " $a"; done; }) )}
144 _systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read a b; do [[ $b == "disabled" ]] && echo " $a"; done; }) )}
145 _systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == "masked" ]] && echo " $a"; done; }) )}
147 # Completion functions for ALL_UNITS
148 for fun in is-active is-failed is-enabled status show mask preset help list-dependencies ; do
149 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
151 _systemctl_really_all_units
152 compadd "$@" -a - _sys_really_all_units
156 # Completion functions for ENABLED_UNITS
157 for fun in disable reenable ; do
158 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
160 _systemctl_enabled_units
161 _systemctl_disabled_units
162 compadd "$@" -a - _sys_enabled_units _sys_disabled_units
166 # Completion functions for DISABLED_UNITS
167 (( $+functions[_systemctl_enable] )) || _systemctl_enable()
169 _systemctl_disabled_units
170 compadd "$@" -a - _sys_disabled_units
173 # Completion functions for FAILED_UNITS
174 (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed()
176 _systemctl_failed_units
177 compadd "$@" -a - _sys_failed_units || _message "no failed unit found"
180 # Completion functions for STARTABLE_UNITS
181 (( $+functions[_systemctl_start] )) || _systemctl_start()
183 _systemctl_inactive_units
184 compadd "$@" -a - _sys_inactive_units
187 # Completion functions for STOPPABLE_UNITS
188 for fun in stop kill try-restart condrestart ; do
189 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
191 _systemctl_active_units
192 compadd "$@" - $( _filter_units_by_property CanStop yes \
193 ${_sys_active_units[*]} )
197 # Completion functions for ISOLATABLE_UNITS
198 (( $+functions[_systemctl_isolate] )) || _systemctl_isolate()
201 compadd "$@" - $( _filter_units_by_property AllowIsolate yes \
202 ${_sys_all_units[*]} )
205 # Completion functions for RELOADABLE_UNITS
206 for fun in reload reload-or-try-restart force-reload ; do
207 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
209 _systemctl_active_units
210 compadd "$@" - $( _filter_units_by_property CanReload yes \
211 ${_sys_active_units[*]} )
215 # Completion functions for RESTARTABLE_UNITS
216 for fun in restart reload-or-restart ; do
217 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
220 compadd "$@" - $( _filter_units_by_property CanStart yes \
221 ${_sys_all_units[*]} | while read line; do \
222 [[ "$line" =~ \.device$ ]] || echo " $line"; \
227 # Completion functions for MASKED_UNITS
228 (( $+functions[_systemctl_unmask] )) || _systemctl_unmask()
230 _systemctl_masked_units
231 compadd "$@" -a - _sys_masked_units || _message "no masked unit found"
234 # Completion functions for JOBS
235 (( $+functions[_systemctl_cancel] )) || _systemctl_cancel()
237 compadd "$@" - $(__systemctl list-jobs \
238 | cut -d' ' -f1 2>/dev/null ) || _message "no job found"
241 # Completion functions for SNAPSHOTS
242 (( $+functions[_systemctl_delete] )) || _systemctl_delete()
244 compadd "$@" - $(__systemctl list-units --type snapshot --all \
245 | cut -d' ' -f1 2>/dev/null ) || _message "no snapshot found"
248 # Completion functions for ENVS
249 for fun in set-environment unset-environment ; do
250 (( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
252 local fun=$0 ; fun=${fun##_systemctl_}
254 if [[ "${fun}" = "set-environment" ]]; then
258 compadd "$@" ${suf} - $(systemctl show-environment \
259 | while read line; do echo " ${line%%\=}";done )
263 (( $+functions[_systemctl_link] )) || _systemctl_link() { _files }
265 # no systemctl completion for:
266 # [STANDALONE]='daemon-reexec daemon-reload default
267 # emergency exit halt kexec list-jobs list-units
268 # list-unit-files poweroff reboot rescue show-environment'
269 # [NAME]='snapshot load'
271 _systemctl_caching_policy()
276 # rebuild if cache is more than a day old
277 oldcache=( "$1"(mh+1) )
278 (( $#oldcache )) && return 0
280 _sysunits=($(__systemctl --all | cut -d' ' -f1))
282 if (( $#_sysunits )); then
283 for unit in $_sysunits; do
284 [[ "$unit" -nt "$1" ]] && return 0
292 local -a _output_opts
293 _output_opts=(short short-monotonic verbose export json json-pretty json-see cat)
294 _describe -t output 'output mode' _output_opts || compadd "$@"
299 _states=(loaded failed active inactive not-found listening running waiting plugged mounted exited dead masked)
300 _values -s , "${_states[@]}"
305 _types=(automount device mount path service snapshot socket swap target timer)
306 _values -s , "${_types[@]}"
310 {-h,--help}'[Show help]' \
311 '--version[Show package version]' \
312 {-t+,--type=}'[List only units of a particular type]:unit type:_unit_types' \
313 '--state=[Display units in the specifyied state]:unit state:_unit_states' \
314 \*{-p+,--property=}'[Show only properties by specific name]:unit property' \
315 {-a,--all}'[Show all units/properties, including dead/empty ones]' \
316 '--reverse[Show reverse dependencies]' \
317 '--after[Show units ordered after]' \
318 '--before[Show units ordered before]' \
319 '--failed[Show only failed units]' \
320 {-l,--full}"[Don't ellipsize unit names on output]" \
321 '--fail[When queueing a new job, fail if conflicting jobs are pending]' \
322 '--show-types[When showing sockets, show socket type]' \
323 '--irreversible[Mark transactions as irreversible]' \
324 '--ignore-dependencies[When queueing a new job, ignore all its dependencies]' \
325 {-i,--ignore-inhibitors}'[When executing a job, ignore jobs dependencies]' \
326 {-q,--quiet}'[Suppress output]' \
327 '--no-block[Do not wait until operation finished]' \
328 '--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \
329 '--no-pager[Do not pipe output into a pager]' \
330 '--system[Connect to system manager]' \
331 '--user[Connect to user service manager]' \
332 "--no-wall[Don't send wall message before halt/power-off/reboot]" \
333 '--global[Enable/disable unit files globally]' \
334 "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \
335 '--no-ask-password[Do not ask for system passwords]' \
336 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
337 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
338 {-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \
339 '--root=[Enable unit files in the specified root directory]:directory:_directories' \
340 '--runtime[Enable unit files only temporarily until next reboot]' \
341 {-H+,--host=}'[Show information for remote host]:userathost:_sd_hosts_or_user_at_host' \
342 {-P,--privileged}'[Acquire privileges before execution]' \
343 {-n+,--lines=}'[Journal entries to show]:number of entries' \
344 {-o+,--output=}'[Change journal output mode]:modes:_outputmodes' \
345 '--plain[When used with list-dependencies, print output as a list]' \
346 '*::systemctl command:_systemctl_command'