]>
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" | |
fa7ea865 | 108 | ) |
51a3b726 | 109 | |
356873dd DS |
110 | local -a groups=( unit machine unit_file job environment manager_state system ) |
111 | local -a _systemctl_cmds | |
112 | for i in $groups; do | |
113 | _systemctl_cmds+=( "${(@P)${:-"${i}_commands"}}" ) | |
114 | done | |
843cfcb1 ZJS |
115 | |
116 | if (( CURRENT == 1 )); then | |
356873dd DS |
117 | _tags ${^groups//_/-}-commands |
118 | while _tags; do | |
119 | for i in $groups; do | |
120 | if _requested ${i//_/-}-commands; then | |
121 | _describe -t ${i//_/-}-commands "${i//_/ } command" ${i}_commands \ | |
122 | && ret=0 | |
123 | fi | |
124 | done | |
125 | done | |
ff7a0685 | 126 | else |
356873dd | 127 | local curcontext="$curcontext" |
843cfcb1 ZJS |
128 | |
129 | cmd="${${_systemctl_cmds[(r)$words[1]:*]%%:*}}" | |
130 | # Deal with any aliases | |
131 | case $cmd in | |
132 | condrestart) cmd="try-restart";; | |
133 | force-reload) cmd="try-reload-or-restart";; | |
134 | esac | |
135 | ||
136 | if (( $#cmd )); then | |
137 | curcontext="${curcontext%:*:*}:systemctl-${cmd}:" | |
138 | ||
139 | local update_policy | |
140 | zstyle -s ":completion:${curcontext}:" cache-policy update_policy | |
141 | if [[ -z "$update_policy" ]]; then | |
142 | zstyle ":completion:${curcontext}:" cache-policy _systemctl_caching_policy | |
143 | fi | |
144 | ||
145 | _call_function ret _systemctl_$cmd || _message 'no more arguments' | |
146 | else | |
147 | _message "unknown systemctl command: $words[1]" | |
148 | fi | |
149 | return ret | |
ff7a0685 | 150 | fi |
ff7a0685 WG |
151 | } |
152 | ||
c501ecd7 | 153 | # @todo _systemd-run has a helper with the same name, so we must redefine |
ff7a0685 WG |
154 | __systemctl() |
155 | { | |
d0fc94a1 | 156 | command systemctl $_sys_service_mgr --full --legend=no --no-pager --plain "$@" 2>/dev/null |
ff7a0685 WG |
157 | } |
158 | ||
159 | ||
160 | # Fills the unit list | |
c501ecd7 | 161 | (( $+functions[_systemctl_all_units] )) || |
843cfcb1 | 162 | _systemctl_all_units() |
ff7a0685 | 163 | { |
8a8caecc | 164 | if _cache_invalid SYS_ALL_UNITS$_sys_service_mgr || ! _retrieve_cache SYS_ALL_UNITS$_sys_service_mgr; |
843cfcb1 | 165 | then |
8139407e | 166 | _sys_all_units=( ${${(f)"$(__systemctl list-units --all)"}%% *} ) |
3b4c6009 | 167 | _store_cache SYS_ALL_UNITS$_sys_service_mgr _sys_all_units |
843cfcb1 | 168 | fi |
ff7a0685 WG |
169 | } |
170 | ||
171 | # Fills the unit list including all file units | |
c501ecd7 | 172 | (( $+functions[_systemctl_really_all_units] )) || |
843cfcb1 | 173 | _systemctl_really_all_units() |
ff7a0685 | 174 | { |
843cfcb1 ZJS |
175 | local -a all_unit_files; |
176 | local -a really_all_units; | |
8a8caecc | 177 | if _cache_invalid SYS_REALLY_ALL_UNITS$_sys_service_mgr || ! _retrieve_cache SYS_REALLY_ALL_UNITS$_sys_service_mgr; |
843cfcb1 | 178 | then |
8139407e | 179 | all_unit_files=( ${${(f)"$(__systemctl list-unit-files)"}%% *} ) |
843cfcb1 ZJS |
180 | _systemctl_all_units |
181 | really_all_units=($_sys_all_units $all_unit_files) | |
182 | _sys_really_all_units=(${(u)really_all_units}) | |
183 | _store_cache SYS_REALLY_ALL_UNITS$_sys_service_mgr _sys_really_all_units | |
184 | fi | |
ff7a0685 WG |
185 | } |
186 | ||
c501ecd7 | 187 | (( $+functions[_filter_units_by_property] )) || |
843cfcb1 ZJS |
188 | _filter_units_by_property() { |
189 | local property=$1 value=$2; shift 2 | |
190 | local -a units; units=("${(q-)@}") | |
191 | local -A props | |
192 | props=(${(f)"$(_call_program units "$service $_sys_service_mgr show --no-pager --property=\"Id,$property\" -- ${units} 2>/dev/null")"}) | |
193 | echo -E - "${(@g:o:)${(k@)props[(Re)$property=$value]}#Id=}" | |
194 | } | |
ff7a0685 | 195 | |
c501ecd7 | 196 | (( $+functions[_systemctl_get_non_template_names] )) || |
c8e2cd79 RP |
197 | _systemctl_get_non_template_names() { |
198 | _systemctl_really_all_units | |
199 | print -r - ${_sys_really_all_units:#*@.*} | |
200 | } | |
4ed14116 | 201 | |
c501ecd7 | 202 | (( $+functions[_systemctl_get_template_names] )) || |
9ec08083 RP |
203 | _systemctl_get_template_names() { |
204 | local pathkind=systemd-search-${_sys_service_mgr##*--}-unit | |
205 | print -r - ${(s-:-)^$(_call_program $pathkind systemd-path $pathkind)}/*@.(${(~j.|.)$(__systemctl --type=help)})(N:t:r) | |
206 | } | |
e9a19bd8 | 207 | |
c501ecd7 | 208 | (( $+functions[_systemctl_active_units] )) || |
2cbda748 RP |
209 | _systemctl_active_units() { |
210 | local pattern | |
211 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
212 | pattern="$PREFIX*$SUFFIX" | |
213 | fi | |
214 | _sys_active_units=( ${${(f)"$(__systemctl list-units $pattern)"}%% *} ) | |
215 | } | |
81333ecf | 216 | |
c501ecd7 | 217 | (( $+functions[_systemctl_startable_units] )) || |
843cfcb1 | 218 | _systemctl_startable_units(){ |
2cbda748 RP |
219 | local pattern |
220 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
221 | pattern="$PREFIX*$SUFFIX" | |
222 | fi | |
843cfcb1 ZJS |
223 | _sys_startable_units=( $( _filter_units_by_property ActiveState inactive $( |
224 | _filter_units_by_property CanStart yes ${${${(f)"$( | |
2cbda748 RP |
225 | __systemctl list-unit-files --state enabled,enabled-runtime,linked,linked-runtime,static,indirect,disabled,generated,transient $pattern |
226 | __systemctl list-units --state inactive,failed $pattern | |
992f51ea | 227 | )"}:#*@.*}%%[[:space:]]*} |
843cfcb1 ZJS |
228 | )) ) |
229 | } | |
81333ecf | 230 | |
c501ecd7 | 231 | (( $+functions[_systemctl_restartable_units] )) || |
843cfcb1 | 232 | _systemctl_restartable_units(){ |
2cbda748 RP |
233 | local pattern |
234 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
235 | pattern="$PREFIX*$SUFFIX" | |
236 | fi | |
843cfcb1 | 237 | _sys_restartable_units=( $( _filter_units_by_property CanStart yes ${${${(f)"$( |
2cbda748 RP |
238 | __systemctl list-unit-files --state enabled,disabled,static $pattern |
239 | __systemctl list-units $pattern | |
992f51ea | 240 | )"}:#*@.*}%%[[:space:]]*} ) ) |
843cfcb1 | 241 | } |
81333ecf | 242 | |
c501ecd7 | 243 | (( $+functions[_systemctl_failed_units] )) || |
8139407e | 244 | _systemctl_failed_units() {_sys_failed_units=( ${${(f)"$(__systemctl list-units --state=failed)"}%% *} ) } |
c501ecd7 | 245 | |
246 | (( $+functions[_systemctl_unit_state] )) || | |
f5b3be30 HT |
247 | _systemctl_unit_state() { |
248 | setopt localoptions extendedglob | |
2cbda748 RP |
249 | local pattern |
250 | if zstyle -T ":completion:$curcontext" use-pattern; then | |
251 | pattern="$PREFIX*$SUFFIX" | |
252 | fi | |
f5b3be30 | 253 | typeset -gA _sys_unit_state |
2cbda748 | 254 | _sys_unit_state=( ${=${${(f)"$(__systemctl list-unit-files $pattern)"}%%[[:space:]]#}% *} ) |
f5b3be30 | 255 | } |
ff7a0685 | 256 | |
67afa931 | 257 | local fun |
ff7a0685 | 258 | # Completion functions for ALL_UNITS |
4ed14116 | 259 | for fun in cat mask ; do |
843cfcb1 ZJS |
260 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
261 | { | |
262 | _systemctl_really_all_units | |
263 | _wanted systemd-units expl unit \ | |
264 | compadd "$@" -a - _sys_really_all_units | |
265 | } | |
ff7a0685 WG |
266 | done |
267 | ||
4ed14116 | 268 | # Completion functions for NONTEMPLATE_UNITS |
c4a2deba | 269 | 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 |
270 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
271 | { | |
272 | _wanted systemd-units expl unit \ | |
273 | compadd "$@" - $(_systemctl_get_non_template_names) | |
274 | } | |
4ed14116 EV |
275 | done |
276 | ||
ff7a0685 | 277 | # Completion functions for ENABLED_UNITS |
e9a19bd8 ZJS |
278 | (( $+functions[_systemctl_disable] )) || _systemctl_disable() |
279 | { | |
fb869ca1 | 280 | local _sys_unit_state; _systemctl_unit_state |
d34b7c11 | 281 | _wanted systemd-units expl 'enabled unit' \ |
843cfcb1 | 282 | compadd "$@" - ${(k)_sys_unit_state[(R)enabled]} |
e9a19bd8 ZJS |
283 | } |
284 | ||
285 | (( $+functions[_systemctl_reenable] )) || _systemctl_reenable() | |
286 | { | |
fb869ca1 | 287 | local _sys_unit_state; _systemctl_unit_state |
d34b7c11 | 288 | _wanted systemd-units expl 'enabled/disabled unit' \ |
843cfcb1 | 289 | compadd "$@" - ${(k)_sys_unit_state[(R)(enabled|disabled)]} $(_systemctl_get_template_names) |
e9a19bd8 | 290 | } |
ff7a0685 WG |
291 | |
292 | # Completion functions for DISABLED_UNITS | |
293 | (( $+functions[_systemctl_enable] )) || _systemctl_enable() | |
294 | { | |
843cfcb1 ZJS |
295 | local _sys_unit_state; _systemctl_unit_state |
296 | _wanted systemd-units expl 'disabled unit' \ | |
297 | compadd "$@" - ${(k)_sys_unit_state[(R)disabled]} $(_systemctl_get_template_names) | |
ff7a0685 WG |
298 | } |
299 | ||
300 | # Completion functions for FAILED_UNITS | |
301 | (( $+functions[_systemctl_reset-failed] )) || _systemctl_reset-failed() | |
302 | { | |
843cfcb1 ZJS |
303 | local _sys_failed_units; _systemctl_failed_units |
304 | _wanted systemd-units expl 'failed unit' \ | |
305 | compadd "$@" -a - _sys_failed_units || _message "no failed unit found" | |
ff7a0685 WG |
306 | } |
307 | ||
308 | # Completion functions for STARTABLE_UNITS | |
309 | (( $+functions[_systemctl_start] )) || _systemctl_start() | |
310 | { | |
843cfcb1 ZJS |
311 | local _sys_startable_units; _systemctl_startable_units |
312 | _wanted systemd-units expl 'startable unit' \ | |
313 | compadd "$@" - ${_sys_startable_units[*]} | |
ff7a0685 WG |
314 | } |
315 | ||
316 | # Completion functions for STOPPABLE_UNITS | |
317 | for fun in stop kill try-restart condrestart ; do | |
843cfcb1 ZJS |
318 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
319 | { | |
320 | local _sys_active_units; _systemctl_active_units | |
321 | _wanted systemd-units expl 'stoppable unit' \ | |
322 | compadd "$@" - $( _filter_units_by_property CanStop yes \ | |
323 | ${_sys_active_units[*]} ) | |
324 | } | |
ff7a0685 WG |
325 | done |
326 | ||
b3d12ac0 RP |
327 | (( $+functions[_systemctl_service-log-level] )) || |
328 | _systemctl_service-log-level() { | |
329 | local -a log_levels=( emerg alert crit err warning notice info debug ) | |
330 | local _sys_active_units; _systemctl_active_units | |
331 | if (( CURRENT == 2 )); then | |
332 | _wanted systemd-units expl 'active unit' \ | |
333 | compadd "$@" -a - _sys_active_units || _message "no units found" | |
334 | else | |
335 | compadd "$@" -a - log_levels | |
336 | fi | |
337 | } | |
338 | ||
339 | (( $+functions[_systemctl_service-log-target] )) || | |
340 | _systemctl_service-log-target() { | |
341 | local -a log_targets=( console kmsg journal syslog null auto ) | |
342 | local _sys_active_units; _systemctl_active_units | |
343 | if (( CURRENT == 2 )); then | |
344 | _wanted systemd-units expl 'active unit' \ | |
345 | compadd "$@" -a - _sys_active_units || _message "no units found" | |
346 | else | |
347 | compadd "$@" -a - log_targets | |
348 | fi | |
349 | } | |
350 | ||
ff7a0685 WG |
351 | # Completion functions for ISOLATABLE_UNITS |
352 | (( $+functions[_systemctl_isolate] )) || _systemctl_isolate() | |
353 | { | |
843cfcb1 ZJS |
354 | _systemctl_all_units |
355 | _wanted systemd-units expl 'isolatable unit' \ | |
356 | compadd "$@" - $( _filter_units_by_property AllowIsolate yes \ | |
357 | ${_sys_all_units[*]} ) | |
ff7a0685 WG |
358 | } |
359 | ||
360 | # Completion functions for RELOADABLE_UNITS | |
aabf5d42 | 361 | for fun in reload try-reload-or-restart force-reload ; do |
843cfcb1 ZJS |
362 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
363 | { | |
364 | local _sys_active_units; _systemctl_active_units | |
365 | _wanted systemd-units expl 'reloadable unit' \ | |
366 | compadd "$@" - $( _filter_units_by_property CanReload yes \ | |
367 | ${_sys_active_units[*]} ) | |
368 | } | |
ff7a0685 WG |
369 | done |
370 | ||
371 | # Completion functions for RESTARTABLE_UNITS | |
372 | for fun in restart reload-or-restart ; do | |
843cfcb1 ZJS |
373 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
374 | { | |
375 | local _sys_restartable_units; _systemctl_restartable_units | |
376 | _wanted systemd-units expl 'restartable unit' \ | |
377 | compadd "$@" - ${_sys_restartable_units[*]} | |
378 | } | |
ff7a0685 WG |
379 | done |
380 | ||
381 | # Completion functions for MASKED_UNITS | |
382 | (( $+functions[_systemctl_unmask] )) || _systemctl_unmask() | |
383 | { | |
843cfcb1 ZJS |
384 | local _sys_unit_state; _systemctl_unit_state |
385 | _wanted systemd-units expl 'masked unit' \ | |
386 | compadd "$@" - ${(k)_sys_unit_state[(R)masked]} || _message "no masked units found" | |
ff7a0685 WG |
387 | } |
388 | ||
389 | # Completion functions for JOBS | |
390 | (( $+functions[_systemctl_cancel] )) || _systemctl_cancel() | |
391 | { | |
843cfcb1 ZJS |
392 | _wanted systemd-jobs expl job \ |
393 | compadd "$@" - ${${(f)"$(__systemctl list-jobs)"}%% *} || | |
394 | _message "no jobs found" | |
ff7a0685 WG |
395 | } |
396 | ||
1cf3c30c ZJS |
397 | # Completion functions for TARGETS |
398 | (( $+functions[_systemctl_set-default] )) || _systemctl_set-default() | |
399 | { | |
843cfcb1 | 400 | _wanted systemd-targets expl target \ |
8139407e | 401 | compadd "$@" - ${${(f)"$(__systemctl list-unit-files --type target --all)"}%% *} || |
843cfcb1 | 402 | _message "no targets found" |
ff7a0685 WG |
403 | } |
404 | ||
405 | # Completion functions for ENVS | |
406 | for fun in set-environment unset-environment ; do | |
843cfcb1 ZJS |
407 | (( $+functions[_systemctl_$fun] )) || _systemctl_$fun() |
408 | { | |
409 | local fun=$0 ; fun=${fun##_systemctl_} | |
410 | local suf | |
411 | if [[ "${fun}" = "set-environment" ]]; then | |
412 | suf='-S=' | |
413 | fi | |
414 | _wanted systemd-environment expl 'environment variable' \ | |
415 | compadd "$@" ${suf} - ${${(f)"$(systemctl show-environment)"}%%=*} | |
416 | } | |
ff7a0685 WG |
417 | done |
418 | ||
34199208 ZJS |
419 | (( $+functions[_systemctl_import-environment] )) || _systemctl_import-environment() |
420 | { | |
421 | _parameters | |
422 | } | |
423 | ||
2c12a402 | 424 | (( $+functions[_systemctl_link] )) || _systemctl_link() { |
843cfcb1 ZJS |
425 | _sd_unit_files |
426 | } | |
ff7a0685 | 427 | |
7b742b31 | 428 | (( $+functions[_systemctl_switch-root] )) || _systemctl_switch-root() { |
843cfcb1 ZJS |
429 | _files |
430 | } | |
7b742b31 | 431 | |
5e8deb94 LB |
432 | (( $+functions[_systemctl_bind] )) || _systemctl_bind() { |
433 | _files | |
434 | } | |
435 | ||
6faecbd3 LB |
436 | (( $+functions[_systemctl_mount-image] )) || _systemctl_mount-image() { |
437 | _files | |
438 | } | |
439 | ||
ff7a0685 | 440 | # no systemctl completion for: |
299c397c | 441 | # [STANDALONE]='daemon-reexec daemon-reload default |
ff7a0685 WG |
442 | # emergency exit halt kexec list-jobs list-units |
443 | # list-unit-files poweroff reboot rescue show-environment' | |
ff7a0685 | 444 | |
c501ecd7 | 445 | (( $+functions[_systemctl_caching_policy] )) || |
843cfcb1 | 446 | _systemctl_caching_policy() |
ff7a0685 | 447 | { |
843cfcb1 | 448 | # rebuild if cache is more than a day old |
110ba0cc | 449 | [[ -n $1(#qNmd+1) ]] && return 0 |
ff7a0685 | 450 | |
110ba0cc RP |
451 | local pathkind=systemd-search-${1##*--}-unit |
452 | for dir in ${(s-:-)^$(_call_program $pathkind systemd-path $pathkind)}; do | |
453 | [[ $dir -nt $1 ]] && return 0 | |
454 | done | |
ff7a0685 | 455 | |
843cfcb1 | 456 | return 1 |
ff7a0685 WG |
457 | } |
458 | ||
c501ecd7 | 459 | (( $+functions[_systemctl_unit_states] )) || |
843cfcb1 ZJS |
460 | _systemctl_unit_states() { |
461 | local -a _states | |
462 | _states=("${(fo)$(__systemctl --state=help)}") | |
463 | _values -s , "${_states[@]}" | |
464 | } | |
298b9e23 | 465 | |
c501ecd7 | 466 | (( $+functions[_systemctl_unit_types] )) || |
843cfcb1 ZJS |
467 | _systemctl_unit_types() { |
468 | local -a _types | |
469 | _types=("${(fo)$(__systemctl -t help)}") | |
470 | _values -s , "${_types[@]}" | |
471 | } | |
298b9e23 | 472 | |
c501ecd7 | 473 | (( $+functions[_systemctl_unit_properties] )) || |
843cfcb1 | 474 | _systemctl_unit_properties() { |
b0d3095f | 475 | local -a _sys_all_properties=( ${(f)"$({{LIBEXECDIR}}/systemd --no-pager --dump-bus-properties 2>/dev/null)"} ) |
ae6fb82c RP |
476 | _wanted systemd-unit-properties expl 'unit property' \ |
477 | _values -s , "${_sys_all_properties[@]}" | |
843cfcb1 | 478 | } |
c0a67aef | 479 | |
c501ecd7 | 480 | (( $+functions[_systemctl_job_modes] )) || |
843cfcb1 ZJS |
481 | _systemctl_job_modes() { |
482 | local -a _modes | |
483 | _modes=(fail replace replace-irreversibly isolate ignore-dependencies ignore-requirements flush) | |
484 | _values -s , "${_modes[@]}" | |
485 | } | |
903e7c37 | 486 | |
46ad9c53 LB |
487 | (( $+functions[_systemctl_timestamp] )) || |
488 | _systemctl_timestamp() { | |
489 | local -a _styles | |
490 | _styles=(help pretty us µs utc us+utc µs+utc) | |
491 | _values -s , "${_styles[@]}" | |
492 | } | |
493 | ||
4327574f FS |
494 | (( $+functions[_systemctl_check_inhibitors] )) || |
495 | _systemctl_check_inhibitors() { | |
496 | local -a _modes | |
497 | _modes=(auto yes no) | |
498 | _values -s , "${_modes[@]}" | |
499 | } | |
500 | ||
e09d0d46 | 501 | # Build arguments for "systemctl" to be used in completion. |
087f777a RP |
502 | # Use the last mode, or --system (they are exclusive and the last one is used). |
503 | local _sys_service_mgr=${words[(R)(--user|--system)]:---system} | |
ff7a0685 | 504 | _arguments -s \ |
20927c0e EK |
505 | '(- *)'{-h,--help}'[Show help]' \ |
506 | '(- *)--version[Show package version]' \ | |
507 | '(-t --type)'{-t+,--type=}'[List only units of a particular type]:unit type:_systemctl_unit_types' \ | |
c501ecd7 | 508 | '--state=[Display units in the specified state]:unit state:_systemctl_unit_states' \ |
509 | '--job-mode=[Specify how to deal with other jobs]:mode:_systemctl_job_modes' \ | |
20927c0e EK |
510 | '(-p --property)'{-p+,--property=}'[Show only properties by specific name]:unit property:_systemctl_unit_properties' \ |
511 | '(-a --all)'{-a,--all}'[Show all units/properties, including dead/empty ones]' \ | |
ff7a0685 WG |
512 | '--reverse[Show reverse dependencies]' \ |
513 | '--after[Show units ordered after]' \ | |
514 | '--before[Show units ordered before]' \ | |
20927c0e | 515 | '(-l --full)'{-l,--full}"[Don't ellipsize unit names on output]" \ |
ff7a0685 | 516 | '--show-types[When showing sockets, show socket type]' \ |
4327574f | 517 | '--check-inhibitors[Specify if inhibitors should be checked]:mode:_systemctl_check_inhibitors' \ |
20927c0e | 518 | '(-q --quiet)'{-q,--quiet}'[Suppress output]' \ |
93b0ec8b | 519 | '--no-warn[Suppress several warnings shown by default]' \ |
ff7a0685 | 520 | '--no-block[Do not wait until operation finished]' \ |
d60bd2ff | 521 | '--legend=no[Do not print a legend, i.e. the column headers and the footer with hints]' \ |
ff7a0685 WG |
522 | '--no-pager[Do not pipe output into a pager]' \ |
523 | '--system[Connect to system manager]' \ | |
524 | '--user[Connect to user service manager]' \ | |
525 | "--no-wall[Don't send wall message before halt/power-off/reboot]" \ | |
3c3335c7 | 526 | '--global[Enable/disable/mask default user unit files globally]' \ |
ff7a0685 WG |
527 | "--no-reload[When enabling/disabling unit files, don't reload daemon configuration]" \ |
528 | '--no-ask-password[Do not ask for system passwords]' \ | |
4ccde410 | 529 | '--kill-whom=[Whom to send signal to]:killwhom:(main control all)' \ |
20927c0e EK |
530 | '(-s --signal)'{-s+,--signal=}'[Which signal to send]:signal:_signals' \ |
531 | '(-f --force)'{-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \ | |
4e93d369 LR |
532 | '--root=[Enable/disable/mask unit files in the specified root directory]:directory:_directories' \ |
533 | '--runtime[Enable/disable/mask unit files only temporarily until next reboot]' \ | |
20927c0e EK |
534 | '(-H --host)'{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \ |
535 | '(-P --privileged)'{-P,--privileged}'[Acquire privileges before execution]' \ | |
536 | '(-n --lines)'{-n+,--lines=}'[Journal entries to show]:number of entries' \ | |
537 | '(-o --output)'{-o+,--output=}'[Change journal output mode]:modes:_sd_outputmodes' \ | |
5bdf2243 | 538 | '--firmware-setup[Tell the firmware to show the setup menu on next boot]' \ |
ff7a0685 | 539 | '--plain[When used with list-dependencies, print output as a list]' \ |
bef19548 | 540 | '--failed[Show failed units]' \ |
46ad9c53 | 541 | '--timestamp=[Change format of printed timestamps]:style:_systemctl_timestamp' \ |
c501ecd7 | 542 | '*::systemctl command:_systemctl_commands' |