]>
Commit | Line | Data |
---|---|---|
682e043c | 1 | #compdef systemctl |
db9ecf05 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
ff7a0685 | 3 | |
c501ecd7 | 4 | (( $+functions[_systemctl_commands] )) || _systemctl_commands() |
ff7a0685 | 5 | { |
356873dd DS |
6 | local expl i |
7 | ||
fa7ea865 | 8 | local -a unit_commands=( |
51a3b726 | 9 | # Unit Commands |
5edea3b7 | 10 | "list-automounts:List automounts" |
73369684 | 11 | "list-paths:List paths" |
843cfcb1 ZJS |
12 | "list-sockets:List sockets" |
13 | "list-timers:List timers" | |
14 | "list-units:List units" | |
15 | "start:Start (activate) one or more units" | |
16 | "stop:Stop (deactivate) one or more units" | |
17 | "reload:Reload one or more units" | |
18 | "restart:Start or restart one or more units" | |
19 | "condrestart:Restart one or more units if active" | |
20 | "try-restart:Restart one or more units if active" | |
21 | "reload-or-restart:Reload one or more units if possible, otherwise start or restart" | |
22 | "force-reload:Reload one or more units if possible, otherwise restart if active" | |
843cfcb1 ZJS |
23 | "try-reload-or-restart:Reload one or more units if possible, otherwise restart if active" |
24 | "isolate:Start one unit and stop all others" | |
25 | "kill:Send signal to processes of a unit" | |
26 | "is-active:Check whether units are active" | |
27 | "is-failed:Check whether units are failed" | |
28 | "status:Show runtime status of one or more units" | |
29 | "show:Show properties of one or more units/jobs or the manager" | |
30 | "cat:Show the source unit files and drop-ins" | |
51a3b726 | 31 | "set-property:Sets one or more properties of a unit" |
b3d12ac0 RP |
32 | "service-log-level:Get or set the logging threshold for service" |
33 | "service-log-target:Get or set the logging target for service" | |
51a3b726 | 34 | "help:Show documentation for specified units" |
843cfcb1 | 35 | "reset-failed:Reset failed state for all, one, or more units" |
51a3b726 | 36 | "list-dependencies:Show unit dependency tree" |
1d8385b4 | 37 | "clean:Remove configuration, state, cache, logs or runtime data of units" |
5e8deb94 | 38 | "bind:Bind mount a path from the host into a unit's namespace" |
6faecbd3 | 39 | "mount-image:Mount an image from the host into a unit's namespace" |
6864f9b9 | 40 | "whoami:Determines as part of which unit the command is being invoked" |
fa7ea865 | 41 | ) |
1d8385b4 | 42 | |
fa7ea865 | 43 | local -a machine_commands=( |
1d8385b4 DS |
44 | # Machine Commands |
45 | "list-machines:List the host and all running local containers" | |
fa7ea865 | 46 | ) |
51a3b726 | 47 | |
fa7ea865 | 48 | local -a unit_file_commands=( |
51a3b726 | 49 | # Unit File Commands |
843cfcb1 ZJS |
50 | "list-unit-files:List installed unit files" |
51 | "enable:Enable one or more unit files" | |
52 | "disable:Disable one or more unit files" | |
843cfcb1 ZJS |
53 | "reenable:Reenable one or more unit files" |
54 | "preset:Enable/disable one or more unit files based on preset configuration" | |
c4e7664d | 55 | "preset-all:Enable/disable all unit files based on preset configuration" |
51a3b726 | 56 | "is-enabled:Check whether unit files are enabled" |
843cfcb1 ZJS |
57 | "mask:Mask one or more units" |
58 | "unmask:Unmask one or more units" | |
59 | "link:Link one or more units files into the search path" | |
51a3b726 DS |
60 | "revert:Revert unit files to their vendor versions" |
61 | "add-wants:Add Wants= dependencies to a unit" | |
62 | "add-requires:Add Requires= dependencies to a unit" | |
63 | "set-default:Set the default target" | |
64 | "get-default:Query the default target" | |
65 | "edit:Edit one or more unit files" | |
fa7ea865 | 66 | ) |
51a3b726 | 67 | |
fa7ea865 | 68 | local -a job_commands=( |
51a3b726 | 69 | # Job Commands |
843cfcb1 ZJS |
70 | "list-jobs:List jobs" |
71 | "cancel:Cancel all, one, or more jobs" | |
fa7ea865 | 72 | ) |
51a3b726 | 73 | |
fa7ea865 | 74 | local -a environment_commands=( |
51a3b726 | 75 | # Environment Commands |
843cfcb1 ZJS |
76 | "show-environment:Dump environment" |
77 | "set-environment:Set one or more environment variables" | |
78 | "unset-environment:Unset one or more environment variables" | |
1d8385b4 | 79 | "import-environment:Import environment variables set on the client" |
fa7ea865 | 80 | ) |
51a3b726 | 81 | |
fa7ea865 | 82 | local -a manager_state_commands=( |
51a3b726 | 83 | # Manager State Commands |
843cfcb1 ZJS |
84 | "daemon-reload:Reload systemd manager configuration" |
85 | "daemon-reexec:Reexecute systemd manager" | |
1d8385b4 DS |
86 | "log-level:Get or set the log level" |
87 | "log-target:Get or set the log target" | |
88 | "service-watchdogs:Get or set the state of software watchdogs" | |
fa7ea865 | 89 | ) |
51a3b726 | 90 | |
fa7ea865 | 91 | local -a system_commands=( |
51a3b726 DS |
92 | # System Commands |
93 | "is-system-running:Query overall status of the system" | |
843cfcb1 ZJS |
94 | "default:Enter system default mode" |
95 | "rescue:Enter system rescue mode" | |
96 | "emergency:Enter system emergency mode" | |
97 | "halt:Shut down and halt the system" | |
98 | "suspend:Suspend the system" | |
99 | "poweroff:Shut down and power-off the system" | |
100 | "reboot:Shut down and reboot the system" | |
050d6d71 | 101 | "soft-reboot:Shut down and reboot the userspace" |
843cfcb1 ZJS |
102 | "kexec:Shut down and reboot the system with kexec" |
103 | "exit:Ask for user instance termination" | |
104 | "switch-root:Change root directory" | |
51a3b726 DS |
105 | "hibernate:Hibernate the system" |
106 | "hybrid-sleep:Hibernate and suspend the system" | |
107 | "suspend-then-hibernate:Suspend the system for a period of time, and then hibernate it" | |
c8342feb | 108 | "sleep:Put the system to sleep" |
fa7ea865 | 109 | ) |
51a3b726 | 110 | |
356873dd DS |
111 | local -a groups=( unit machine unit_file job environment manager_state system ) |
112 | local -a _systemctl_cmds | |
113 | for i in $groups; do | |
114 | _systemctl_cmds+=( "${(@P)${:-"${i}_commands"}}" ) | |
115 | done | |
843cfcb1 ZJS |
116 | |
117 | if (( CURRENT == 1 )); then | |
356873dd DS |
118 | _tags ${^groups//_/-}-commands |
119 | while _tags; do | |
120 | for i in $groups; do | |
121 | if _requested ${i//_/-}-commands; then | |
12e64a48 EK |
122 | _describe -t ${i//_/-}-commands "${i//_/ } command" ${i}_commands && |
123 | ret=0 | |
356873dd DS |
124 | fi |
125 | done | |
126 | done | |
ff7a0685 | 127 | else |
356873dd | 128 | local curcontext="$curcontext" |
843cfcb1 ZJS |
129 | |
130 | cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}" | |
131 | # Deal with any aliases | |
132 | case $cmd in | |
133 | condrestart) cmd="try-restart";; | |
134 | force-reload) cmd="try-reload-or-restart";; | |
135 | esac | |
136 | ||
137 | if (( $#cmd )); then | |
138 | curcontext="${curcontext%:*:*}:systemctl-${cmd}:" | |
139 | ||
140 | local update_policy | |
141 | zstyle -s ":completion:${curcontext}:" cache-policy update_policy | |
142 | if [[ -z "$update_policy" ]]; then | |
143 | zstyle ":completion:${curcontext}:" cache-policy _systemctl_caching_policy | |
144 | fi | |
145 | ||
146 | _call_function ret _systemctl_$cmd || _message 'no more arguments' | |
147 | else | |
148 | _message "unknown systemctl command: $words[1]" | |
149 | fi | |
150 | return ret | |
ff7a0685 | 151 | fi |
ff7a0685 WG |
152 | } |
153 | ||
c501ecd7 | 154 | # @todo _systemd-run has a helper with the same name, so we must redefine |
ff7a0685 WG |
155 | __systemctl() |
156 | { | |
d0fc94a1 | 157 | command systemctl $_sys_service_mgr --full --legend=no --no-pager --plain "$@" 2>/dev/null |
ff7a0685 WG |
158 | } |
159 | ||
160 | ||
161 | # Fills the unit list | |
c501ecd7 | 162 | (( $+functions[_systemctl_all_units] )) || |
843cfcb1 | 163 | _systemctl_all_units() |
ff7a0685 | 164 | { |
5300aa7a | 165 | if _cache_invalid SYS_ALL_UNITS$_sys_service_mgr || ! _retrieve_cache SYS_ALL_UNITS$_sys_service_mgr |
843cfcb1 | 166 | then |
8139407e | 167 | _sys_all_units=( ${${(f)"$(__systemctl list-units --all)"}%% *} ) |
3b4c6009 | 168 | _store_cache SYS_ALL_UNITS$_sys_service_mgr _sys_all_units |
843cfcb1 | 169 | fi |
ff7a0685 WG |
170 | } |
171 | ||
172 | # Fills the unit list including all file units | |
c501ecd7 | 173 | (( $+functions[_systemctl_really_all_units] )) || |
843cfcb1 | 174 | _systemctl_really_all_units() |
ff7a0685 | 175 | { |
5300aa7a EK |
176 | local -a all_unit_files |
177 | local -a really_all_units | |
178 | if _cache_invalid SYS_REALLY_ALL_UNITS$_sys_service_mgr || ! _retrieve_cache SYS_REALLY_ALL_UNITS$_sys_service_mgr | |
843cfcb1 | 179 | then |
8139407e | 180 | all_unit_files=( ${${(f)"$(__systemctl list-unit-files)"}%% *} ) |
843cfcb1 ZJS |
181 | _systemctl_all_units |
182 | really_all_units=($_sys_all_units $all_unit_files) | |
183 | _sys_really_all_units=(${(u)really_all_units}) | |
184 | _store_cache SYS_REALLY_ALL_UNITS$_sys_service_mgr _sys_really_all_units | |
185 | fi | |
ff7a0685 WG |
186 | } |
187 | ||
c501ecd7 | 188 | (( $+functions[_filter_units_by_property] )) || |
843cfcb1 ZJS |
189 | _filter_units_by_property() { |
190 | local property=$1 value=$2; shift 2 | |
191 | local -a units; units=("${(q-)@}") | |
192 | local -A props | |
193 | props=(${(f)"$(_call_program units "$service $_sys_service_mgr show --no-pager --property=\"Id,$property\" -- ${units} 2>/dev/null")"}) | |
3ceb4d24 | 194 | echo -E - "${(@)${(k@)props[(Re)$property=$value]}#Id=}" |
843cfcb1 | 195 | } |
ff7a0685 | 196 | |
c501ecd7 | 197 | (( $+functions[_systemctl_get_non_template_names] )) || |
c8e2cd79 RP |
198 | _systemctl_get_non_template_names() { |
199 | _systemctl_really_all_units | |
200 | print -r - ${_sys_really_all_units:#*@.*} | |
201 | } | |
4ed14116 | 202 | |
c501ecd7 | 203 | (( $+functions[_systemctl_get_template_names] )) || |
9ec08083 RP |
204 | _systemctl_get_template_names() { |
205 | local pathkind=systemd-search-${_sys_service_mgr##*--}-unit | |
206 | print -r - ${(s-:-)^$(_call_program $pathkind systemd-path $pathkind)}/*@.(${(~j.|.)$(__systemctl --type=help)})(N:t:r) | |
207 | } | |
e9a19bd8 | 208 | |
c501ecd7 | 209 | (( $+functions[_systemctl_active_units] )) || |
2cbda748 RP |
210 | _systemctl_active_units() { |
211 | local pattern | |
212 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
213 | pattern="$PREFIX*$SUFFIX" | |
214 | fi | |
215 | _sys_active_units=( ${${(f)"$(__systemctl list-units $pattern)"}%% *} ) | |
216 | } | |
81333ecf | 217 | |
c501ecd7 | 218 | (( $+functions[_systemctl_startable_units] )) || |
843cfcb1 | 219 | _systemctl_startable_units(){ |
2cbda748 RP |
220 | local pattern |
221 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
222 | pattern="$PREFIX*$SUFFIX" | |
223 | fi | |
843cfcb1 ZJS |
224 | _sys_startable_units=( $( _filter_units_by_property ActiveState inactive $( |
225 | _filter_units_by_property CanStart yes ${${${(f)"$( | |
2cbda748 RP |
226 | __systemctl list-unit-files --state enabled,enabled-runtime,linked,linked-runtime,static,indirect,disabled,generated,transient $pattern |
227 | __systemctl list-units --state inactive,failed $pattern | |
992f51ea | 228 | )"}:#*@.*}%%[[:space:]]*} |
843cfcb1 ZJS |
229 | )) ) |
230 | } | |
81333ecf | 231 | |
c501ecd7 | 232 | (( $+functions[_systemctl_restartable_units] )) || |
843cfcb1 | 233 | _systemctl_restartable_units(){ |
2cbda748 RP |
234 | local pattern |
235 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
236 | pattern="$PREFIX*$SUFFIX" | |
237 | fi | |
843cfcb1 | 238 | _sys_restartable_units=( $( _filter_units_by_property CanStart yes ${${${(f)"$( |
2cbda748 RP |
239 | __systemctl list-unit-files --state enabled,disabled,static $pattern |
240 | __systemctl list-units $pattern | |
992f51ea | 241 | )"}:#*@.*}%%[[:space:]]*} ) ) |
843cfcb1 | 242 | } |
81333ecf | 243 | |
c501ecd7 | 244 | (( $+functions[_systemctl_failed_units] )) || |
8139407e | 245 | _systemctl_failed_units() {_sys_failed_units=( ${${(f)"$(__systemctl list-units --state=failed)"}%% *} ) } |
c501ecd7 | 246 | |
247 | (( $+functions[_systemctl_unit_state] )) || | |
f5b3be30 HT |
248 | _systemctl_unit_state() { |
249 | setopt localoptions extendedglob | |
2cbda748 RP |
250 | local pattern |
251 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
252 | pattern="$PREFIX*$SUFFIX" | |
253 | fi | |
f5b3be30 | 254 | typeset -gA _sys_unit_state |
2cbda748 | 255 | _sys_unit_state=( ${=${${(f)"$(__systemctl list-unit-files $pattern)"}%%[[:space:]]#}% *} ) |
f5b3be30 | 256 | } |
ff7a0685 | 257 | |
67afa931 | 258 | local fun |
ff7a0685 | 259 | # Completion functions for ALL_UNITS |
4ed14116 | 260 | for fun in cat mask ; do |
843cfcb1 ZJS |
261 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
262 | { | |
263 | _systemctl_really_all_units | |
264 | _wanted systemd-units expl unit \ | |
265 | compadd "$@" -a - _sys_really_all_units | |
266 | } | |
ff7a0685 WG |
267 | done |
268 | ||
4ed14116 | 269 | # Completion functions for NONTEMPLATE_UNITS |
c4a2deba | 270 | for fun in is-active is-failed is-enabled status show preset help list-dependencies edit revert add-wants add-requires set-property; do |
843cfcb1 ZJS |
271 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
272 | { | |
273 | _wanted systemd-units expl unit \ | |
274 | compadd "$@" - $(_systemctl_get_non_template_names) | |
275 | } | |
4ed14116 EV |
276 | done |
277 | ||
ff7a0685 | 278 | # Completion functions for ENABLED_UNITS |
e9a19bd8 ZJS |
279 | (( $+functions[_systemctl_disable] )) || _systemctl_disable() |
280 | { | |
fb869ca1 | 281 | local _sys_unit_state; _systemctl_unit_state |
d34b7c11 | 282 | _wanted systemd-units expl 'enabled unit' \ |
843cfcb1 | 283 | compadd "$@" - ${(k)_sys_unit_state[(R)enabled]} |
e9a19bd8 ZJS |
284 | } |
285 | ||
286 | (( $+functions[_systemctl_reenable] )) || _systemctl_reenable() | |
287 | { | |
fb869ca1 | 288 | local _sys_unit_state; _systemctl_unit_state |
d34b7c11 | 289 | _wanted systemd-units expl 'enabled/disabled unit' \ |
843cfcb1 | 290 | compadd "$@" - ${(k)_sys_unit_state[(R)(enabled|disabled)]} $(_systemctl_get_template_names) |
e9a19bd8 | 291 | } |
ff7a0685 WG |
292 | |
293 | # Completion functions for DISABLED_UNITS | |
294 | (( $+functions[_systemctl_enable] )) || _systemctl_enable() | |
295 | { | |
843cfcb1 ZJS |
296 | local _sys_unit_state; _systemctl_unit_state |
297 | _wanted systemd-units expl 'disabled unit' \ | |
298 | compadd "$@" - ${(k)_sys_unit_state[(R)disabled]} $(_systemctl_get_template_names) | |
ff7a0685 WG |
299 | } |
300 | ||
301 | # Completion functions for FAILED_UNITS | |
302 | (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed() | |
303 | { | |
843cfcb1 ZJS |
304 | local _sys_failed_units; _systemctl_failed_units |
305 | _wanted systemd-units expl 'failed unit' \ | |
306 | compadd "$@" -a - _sys_failed_units || _message "no failed unit found" | |
ff7a0685 WG |
307 | } |
308 | ||
309 | # Completion functions for STARTABLE_UNITS | |
310 | (( $+functions[_systemctl_start] )) || _systemctl_start() | |
311 | { | |
843cfcb1 ZJS |
312 | local _sys_startable_units; _systemctl_startable_units |
313 | _wanted systemd-units expl 'startable unit' \ | |
314 | compadd "$@" - ${_sys_startable_units[*]} | |
ff7a0685 WG |
315 | } |
316 | ||
317 | # Completion functions for STOPPABLE_UNITS | |
318 | for fun in stop kill try-restart condrestart ; do | |
843cfcb1 ZJS |
319 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
320 | { | |
321 | local _sys_active_units; _systemctl_active_units | |
322 | _wanted systemd-units expl 'stoppable unit' \ | |
323 | compadd "$@" - $( _filter_units_by_property CanStop yes \ | |
324 | ${_sys_active_units[*]} ) | |
325 | } | |
ff7a0685 WG |
326 | done |
327 | ||
b3d12ac0 RP |
328 | (( $+functions[_systemctl_service-log-level] )) || |
329 | _systemctl_service-log-level() { | |
330 | local -a log_levels=( emerg alert crit err warning notice info debug ) | |
331 | local _sys_active_units; _systemctl_active_units | |
332 | if (( CURRENT == 2 )); then | |
333 | _wanted systemd-units expl 'active unit' \ | |
334 | compadd "$@" -a - _sys_active_units || _message "no units found" | |
335 | else | |
336 | compadd "$@" -a - log_levels | |
337 | fi | |
338 | } | |
339 | ||
340 | (( $+functions[_systemctl_service-log-target] )) || | |
341 | _systemctl_service-log-target() { | |
342 | local -a log_targets=( console kmsg journal syslog null auto ) | |
343 | local _sys_active_units; _systemctl_active_units | |
344 | if (( CURRENT == 2 )); then | |
345 | _wanted systemd-units expl 'active unit' \ | |
346 | compadd "$@" -a - _sys_active_units || _message "no units found" | |
347 | else | |
348 | compadd "$@" -a - log_targets | |
349 | fi | |
350 | } | |
351 | ||
ff7a0685 WG |
352 | # Completion functions for ISOLATABLE_UNITS |
353 | (( $+functions[_systemctl_isolate] )) || _systemctl_isolate() | |
354 | { | |
843cfcb1 ZJS |
355 | _systemctl_all_units |
356 | _wanted systemd-units expl 'isolatable unit' \ | |
357 | compadd "$@" - $( _filter_units_by_property AllowIsolate yes \ | |
358 | ${_sys_all_units[*]} ) | |
ff7a0685 WG |
359 | } |
360 | ||
361 | # Completion functions for RELOADABLE_UNITS | |
aabf5d42 | 362 | for fun in reload try-reload-or-restart force-reload ; do |
843cfcb1 ZJS |
363 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
364 | { | |
365 | local _sys_active_units; _systemctl_active_units | |
366 | _wanted systemd-units expl 'reloadable unit' \ | |
367 | compadd "$@" - $( _filter_units_by_property CanReload yes \ | |
368 | ${_sys_active_units[*]} ) | |
369 | } | |
ff7a0685 WG |
370 | done |
371 | ||
372 | # Completion functions for RESTARTABLE_UNITS | |
373 | for fun in restart reload-or-restart ; do | |
843cfcb1 ZJS |
374 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
375 | { | |
376 | local _sys_restartable_units; _systemctl_restartable_units | |
377 | _wanted systemd-units expl 'restartable unit' \ | |
378 | compadd "$@" - ${_sys_restartable_units[*]} | |
379 | } | |
ff7a0685 WG |
380 | done |
381 | ||
382 | # Completion functions for MASKED_UNITS | |
383 | (( $+functions[_systemctl_unmask] )) || _systemctl_unmask() | |
384 | { | |
843cfcb1 ZJS |
385 | local _sys_unit_state; _systemctl_unit_state |
386 | _wanted systemd-units expl 'masked unit' \ | |
387 | compadd "$@" - ${(k)_sys_unit_state[(R)masked]} || _message "no masked units found" | |
ff7a0685 WG |
388 | } |
389 | ||
390 | # Completion functions for JOBS | |
391 | (( $+functions[_systemctl_cancel] )) || _systemctl_cancel() | |
392 | { | |
843cfcb1 ZJS |
393 | _wanted systemd-jobs expl job \ |
394 | compadd "$@" - ${${(f)"$(__systemctl list-jobs)"}%% *} || | |
395 | _message "no jobs found" | |
ff7a0685 WG |
396 | } |
397 | ||
1cf3c30c ZJS |
398 | # Completion functions for TARGETS |
399 | (( $+functions[_systemctl_set-default] )) || _systemctl_set-default() | |
400 | { | |
843cfcb1 | 401 | _wanted systemd-targets expl target \ |
8139407e | 402 | compadd "$@" - ${${(f)"$(__systemctl list-unit-files --type target --all)"}%% *} || |
843cfcb1 | 403 | _message "no targets found" |
ff7a0685 WG |
404 | } |
405 | ||
406 | # Completion functions for ENVS | |
407 | for fun in set-environment unset-environment ; do | |
843cfcb1 ZJS |
408 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
409 | { | |
410 | local fun=$0 ; fun=${fun##_systemctl_} | |
411 | local suf | |
412 | if [[ "${fun}" = "set-environment" ]]; then | |
413 | suf='-S=' | |
414 | fi | |
415 | _wanted systemd-environment expl 'environment variable' \ | |
6d07d23b | 416 | compadd "$@" ${suf} - ${${(f)"$(systemctl "$_sys_service_mgr" show-environment)"}%%=*} |
843cfcb1 | 417 | } |
ff7a0685 WG |
418 | done |
419 | ||
34199208 ZJS |
420 | (( $+functions[_systemctl_import-environment] )) || _systemctl_import-environment() |
421 | { | |
422 | _parameters | |
423 | } | |
424 | ||
2c12a402 | 425 | (( $+functions[_systemctl_link] )) || _systemctl_link() { |
843cfcb1 ZJS |
426 | _sd_unit_files |
427 | } | |
ff7a0685 | 428 | |
7b742b31 | 429 | (( $+functions[_systemctl_switch-root] )) || _systemctl_switch-root() { |
843cfcb1 ZJS |
430 | _files |
431 | } | |
7b742b31 | 432 | |
5e8deb94 LB |
433 | (( $+functions[_systemctl_bind] )) || _systemctl_bind() { |
434 | _files | |
435 | } | |
436 | ||
6faecbd3 LB |
437 | (( $+functions[_systemctl_mount-image] )) || _systemctl_mount-image() { |
438 | _files | |
439 | } | |
440 | ||
ff7a0685 | 441 | # no systemctl completion for: |
299c397c | 442 | # [STANDALONE]='daemon-reexec daemon-reload default |
ff7a0685 WG |
443 | # emergency exit halt kexec list-jobs list-units |
444 | # list-unit-files poweroff reboot rescue show-environment' | |
ff7a0685 | 445 | |
c501ecd7 | 446 | (( $+functions[_systemctl_caching_policy] )) || |
843cfcb1 | 447 | _systemctl_caching_policy() |
ff7a0685 | 448 | { |
843cfcb1 | 449 | # rebuild if cache is more than a day old |
110ba0cc | 450 | [[ -n $1(#qNmd+1) ]] && return 0 |
ff7a0685 | 451 | |
110ba0cc RP |
452 | local pathkind=systemd-search-${1##*--}-unit |
453 | for dir in ${(s-:-)^$(_call_program $pathkind systemd-path $pathkind)}; do | |
454 | [[ $dir -nt $1 ]] && return 0 | |
455 | done | |
ff7a0685 | 456 | |
843cfcb1 | 457 | return 1 |
ff7a0685 WG |
458 | } |
459 | ||
c501ecd7 | 460 | (( $+functions[_systemctl_unit_states] )) || |
843cfcb1 ZJS |
461 | _systemctl_unit_states() { |
462 | local -a _states | |
463 | _states=("${(fo)$(__systemctl --state=help)}") | |
464 | _values -s , "${_states[@]}" | |
465 | } | |
298b9e23 | 466 | |
c501ecd7 | 467 | (( $+functions[_systemctl_unit_types] )) || |
843cfcb1 ZJS |
468 | _systemctl_unit_types() { |
469 | local -a _types | |
470 | _types=("${(fo)$(__systemctl -t help)}") | |
471 | _values -s , "${_types[@]}" | |
472 | } | |
298b9e23 | 473 | |
c501ecd7 | 474 | (( $+functions[_systemctl_unit_properties] )) || |
843cfcb1 | 475 | _systemctl_unit_properties() { |
dfe6b3fa | 476 | local -a _sys_all_properties=( ${(f)"$({{LIBEXECDIR}}/systemd --no-pager --dump-bus-properties 2>/dev/null)"} ) |
ae6fb82c | 477 | _wanted systemd-unit-properties expl 'unit property' \ |
dfe6b3fa | 478 | _values -s , "${_sys_all_properties[@]}" |
843cfcb1 | 479 | } |
c0a67aef | 480 | |
c501ecd7 | 481 | (( $+functions[_systemctl_job_modes] )) || |
843cfcb1 ZJS |
482 | _systemctl_job_modes() { |
483 | local -a _modes | |
484 | _modes=(fail replace replace-irreversibly isolate ignore-dependencies ignore-requirements flush) | |
485 | _values -s , "${_modes[@]}" | |
486 | } | |
903e7c37 | 487 | |
46ad9c53 LB |
488 | (( $+functions[_systemctl_timestamp] )) || |
489 | _systemctl_timestamp() { | |
490 | local -a _styles | |
491 | _styles=(help pretty us µs utc us+utc µs+utc) | |
492 | _values -s , "${_styles[@]}" | |
493 | } | |
494 | ||
4327574f FS |
495 | (( $+functions[_systemctl_check_inhibitors] )) || |
496 | _systemctl_check_inhibitors() { | |
497 | local -a _modes | |
498 | _modes=(auto yes no) | |
499 | _values -s , "${_modes[@]}" | |
500 | } | |
501 | ||
e09d0d46 | 502 | # Build arguments for "systemctl" to be used in completion. |
087f777a RP |
503 | # Use the last mode, or --system (they are exclusive and the last one is used). |
504 | local _sys_service_mgr=${words[(R)(--user|--system)]:---system} | |
ff7a0685 | 505 | _arguments -s \ |
20927c0e EK |
506 | '(- *)'{-h,--help}'[Show help]' \ |
507 | '(- *)--version[Show package version]' \ | |
508 | '(-t --type)'{-t+,--type=}'[List only units of a particular type]:unit type:_systemctl_unit_types' \ | |
c501ecd7 | 509 | '--state=[Display units in the specified state]:unit state:_systemctl_unit_states' \ |
510 | '--job-mode=[Specify how to deal with other jobs]:mode:_systemctl_job_modes' \ | |
20927c0e EK |
511 | '(-p --property)'{-p+,--property=}'[Show only properties by specific name]:unit property:_systemctl_unit_properties' \ |
512 | '(-a --all)'{-a,--all}'[Show all units/properties, including dead/empty ones]' \ | |
ff7a0685 WG |
513 | '--reverse[Show reverse dependencies]' \ |
514 | '--after[Show units ordered after]' \ | |
515 | '--before[Show units ordered before]' \ | |
20927c0e | 516 | '(-l --full)'{-l,--full}"[Don't ellipsize unit names on output]" \ |
ff7a0685 | 517 | '--show-types[When showing sockets, show socket type]' \ |
4327574f | 518 | '--check-inhibitors[Specify if inhibitors should be checked]:mode:_systemctl_check_inhibitors' \ |
20927c0e | 519 | '(-q --quiet)'{-q,--quiet}'[Suppress output]' \ |
93b0ec8b | 520 | '--no-warn[Suppress several warnings shown by default]' \ |
ff7a0685 | 521 | '--no-block[Do not wait until operation finished]' \ |
d60bd2ff | 522 | '--legend=no[Do not print a legend, i.e. the column headers and the footer with hints]' \ |
ff7a0685 WG |
523 | '--no-pager[Do not pipe output into a pager]' \ |
524 | '--system[Connect to system manager]' \ | |
525 | '--user[Connect to user service manager]' \ | |
526 | "--no-wall[Don't send wall message before halt/power-off/reboot]" \ | |
3c3335c7 | 527 | '--global[Enable/disable/mask default user unit files globally]' \ |
ff7a0685 WG |
528 | "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \ |
529 | '--no-ask-password[Do not ask for system passwords]' \ | |
4ccde410 | 530 | '--kill-whom=[Whom to send signal to]:killwhom:(main control all)' \ |
20927c0e EK |
531 | '(-s --signal)'{-s+,--signal=}'[Which signal to send]:signal:_signals' \ |
532 | '(-f --force)'{-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \ | |
4e93d369 LR |
533 | '--root=[Enable/disable/mask unit files in the specified root directory]:directory:_directories' \ |
534 | '--runtime[Enable/disable/mask unit files only temporarily until next reboot]' \ | |
20927c0e EK |
535 | '(-H --host)'{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \ |
536 | '(-P --privileged)'{-P,--privileged}'[Acquire privileges before execution]' \ | |
537 | '(-n --lines)'{-n+,--lines=}'[Journal entries to show]:number of entries' \ | |
538 | '(-o --output)'{-o+,--output=}'[Change journal output mode]:modes:_sd_outputmodes' \ | |
5bdf2243 | 539 | '--firmware-setup[Tell the firmware to show the setup menu on next boot]' \ |
ff7a0685 | 540 | '--plain[When used with list-dependencies, print output as a list]' \ |
bef19548 | 541 | '--failed[Show failed units]' \ |
46ad9c53 | 542 | '--timestamp=[Change format of printed timestamps]:style:_systemctl_timestamp' \ |
c501ecd7 | 543 | '*::systemctl command:_systemctl_commands' |