]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/zsh/_systemd
70746efeb8b7c01d855e1e414c04f8e5ee3cb717
[thirdparty/systemd.git] / shell-completion / zsh / _systemd
1 #compdef timedatectl systemd-coredumpctl udevadm systemd-analyze systemd-cat systemd-ask-password systemd-cgls systemd-cgtop systemd-delta systemd-detect-virt systemd-inhibit systemd-machine-id-setup systemd-notify systemd-nspawn systemd-tmpfiles systemd-tty-ask-password-agent machinectl
2
3 _ctls()
4 {
5 local curcontext="$curcontext" state lstate line
6 case "$service" in
7 systemd-coredumpctl)
8 _arguments \
9 {-o,--output=}'[Write output to FILE]:output file:_files' \
10 '--no-pager[Do not pipe output into a pager]' \
11 {-h,--help}'[Show this help]' \
12 '--version[Show package version]' \
13 '*::systemd-coredumpctl commands:_systemd-coredumpctl_command'
14
15 ;;
16 timedatectl)
17 _arguments -s \
18 {-h,--help}'[Show this help]' \
19 '--version[Show package version]' \
20 '--adjust-system-clock[Adjust system clock when changing local RTC mode]' \
21 '--no-pager[Do not pipe output into a pager]' \
22 '--no-ask-password[Do not prompt for password]' \
23 {-H,--host=}'[Operate on remote host]:userathost:_hosts_or_user_at_host' \
24 '*::timedatectl commands:_timedatectl_command'
25 ;;
26 udevadm)
27 _arguments \
28 '--debug[Print debug messages to stderr]' \
29 '--version[Print version number]' \
30 '--help[Print help text]' \
31 '*::udevadm commands:_udevadm_command'
32 ;;
33 systemd-analyze)
34 _arguments \
35 {-h,--help}'[Show help text.]' \
36 '--user[Shows performance data of user sessions instead of the system manager.]' \
37 '--order[When generating graph for dot, show only order]' \
38 '--require[When generating graph for dot, show only requirement]' \
39 '*::systemd-analyze commands:_systemd_analyze_command'
40 ;;
41 systemd-ask-password)
42 _arguments \
43 {-h,--help}'[Show this help]' \
44 '--icon=[Icon name]' \
45 '--timeout=[Timeout in sec]' \
46 '--no-tty[Ask question via agent even on TTY]' \
47 '--accept-cached[Accept cached passwords]' \
48 '--multiple[List multiple passwords if available]'
49 ;;
50 systemd-cat)
51 _arguments \
52 {-h,--help}'[Show this help]' \
53 '--version[Show package version.]' \
54 {-t,--identifier=}'[Set syslog identifier.]' \
55 {-p,--priority=}'[Set priority value.]:value:({0..7})' \
56 '--level-prefix=[Control whether level prefix shall be parsed.]:boolean:(1 0)' \
57 ':Message'
58 ;;
59 systemd-cgls)
60 _arguments \
61 {-h,--help}'[Show this help]' \
62 '--version[Show package version]' \
63 '--no-pager[Do not pipe output into a pager]' \
64 {-a,--all}'[Show all groups, including empty]' \
65 '-k[Include kernel threads in output]' \
66 ':cgroups:(cpuset cpu cpuacct memory devices freezer net_cls blkio)'
67 ;;
68 systemd-cgtop)
69 _arguments \
70 {-h,--help}'[Show this help]' \
71 '--version[Print version and exit]' \
72 '(-c -m -i -t)-p[Order by path]' \
73 '(-c -p -m -i)-t[Order by number of tasks]' \
74 '(-m -p -i -t)-c[Order by CPU load]' \
75 '(-c -p -i -t)-m[Order by memory load]' \
76 '(-c -m -p -t)-i[Order by IO load]' \
77 {-d,--delay=}'[Specify delay]' \
78 {-n,--iterations=}'[Run for N iterations before exiting]' \
79 {-b,--batch}'[Run in batch mode, accepting no input]' \
80 '--depth=[Maximum traversal depth]'
81 ;;
82 systemd-delta)
83 _arguments \
84 {-h,--help}'[Show this help]' \
85 '--version[Show package version]' \
86 '--no-pager[Do not pipe output into a pager]' \
87 '--diff=[Show a diff when overridden files differ]:boolean:(1 0)' \
88 {-t,--type=}'[Only display a selected set of override types]:types:(masked equivalent redirected overridden unchanged)' \
89 ':SUFFIX:(tmpfiles.d sysctl.d systemd/system)'
90 ;;
91 systemd-detect-virt)
92 _arguments \
93 {-h,--help}'[Show this help]' \
94 '--version[Show package version]' \
95 {-c,--container}'[Only detect whether we are run in a container]' \
96 {-v,--vm}'[Only detect whether we are run in a VM]' \
97 {-q,--quiet}"[Don't output anything, just set return value]"
98 ;;
99 systemd-inhibit)
100 _arguments \
101 {-h,--help}'[Show this help]' \
102 '--version[Show package version]' \
103 '--what=[Operations to inhibit]:options:(shutdown sleep idle handle-power-key handle-suspend-key handle-hibernate-key handle-lid-switch)' \
104 '--who=[A descriptive string who is inhibiting]' \
105 '--why=[A descriptive string why is being inhibited]' \
106 '--mode=[One of block or delay]' \
107 '--list[List active inhibitors]' \
108 '*:commands:_systemd_inhibit_command'
109 ;;
110 systemd-machine-id-setup)
111 _arguments \
112 {-h,--help}'[Show this help]' \
113 '--version[Show package version]'
114 ;;
115 systemd-notify)
116 _arguments \
117 {-h,--help}'[Show this help]' \
118 '--version[Show package version]' \
119 '--ready[Inform the init system about service start-up completion.]' \
120 '--pid=[Inform the init system about the main PID of the daemon]' \
121 '--status=[Send a free-form status string for the daemon to the init systemd]' \
122 '--booted[Returns 0 if the system was booted up with systemd]' \
123 '--readahead=[Controls disk read-ahead operations]:arguments:(cancel done noreply)'
124 ;;
125 systemd-nspawn)
126 _arguments \
127 {-h,--help}'[Show this help]' \
128 {--directory=,-D}'[Directory to use as file system root for the namespace container. If omitted the current directory will be used.]:directories:_directories' \
129 {--boot,-b}'[Automatically search for an init binary and invoke it instead of a shell or a user supplied program.]' \
130 {--user=,-u}'[Run the command under specified user, create home directory and cd into it.]' \
131 '--uuid=[Set the specified uuid for the container.]' \
132 {--controllers=,-C}'[Makes the container appear in other hierarchies than the name=systemd:/ one. Takes a comma-separated list of controllers.]' \
133 '--private-network[Turn off networking in the container. This makes all network interfaces unavailable in the container, with the exception of the loopback device.]' \
134 '--read-only[Mount the root file system read only for the container.]' \
135 '--capability=[List one or more additional capabilities to grant the container.]:capabilities:_systemd-nspawn' \
136 "--link-journal=[Control whether the container's journal shall be made visible to the host system.]:options:(no, host, guest, auto)" \
137 '-j[Equivalent to --link-journal=guest.]'
138 ;;
139 systemd-tmpfiles)
140 _arguments \
141 '--create[Create, set ownership/permissions based on the config files.]' \
142 '--clean[Clean up all files and directories with an age parameter configured.]' \
143 '--remove[All files and directories marked with r, R in the configuration files are removed.]' \
144 '--prefix=[Only apply rules that apply to paths with the specified prefix.]' \
145 '--exclude-prefix=[Ignore rules that apply to paths with the specified prefix.]' \
146 '--help[Prints a short help text and exits.]' \
147 '*::files:_files'
148 ;;
149 systemd-tty-ask-password-agent)
150 _arguments \
151 {-h,--help}'[Prints a short help text and exits.]' \
152 '--version[Prints a short version string and exits.]' \
153 '--list[Lists all currently pending system password requests.]' \
154 '--query[Process all currently pending system password requests by querying the user on the calling TTY.]' \
155 '--watch[Continuously process password requests.]' \
156 '--wall[Forward password requests to wall(1).]' \
157 '--plymouth[Ask question with plymouth(8).]' \
158 '--console[Ask question on /dev/console.]'
159 ;;
160 machinectl)
161 _arguments \
162 {-h,--help}'[Prints a short help text and exits.]' \
163 '--version[Prints a short version string and exits.]' \
164 {-p,--property=}'[Limit output to specified property.]:property:(Name Id Timestamp TimestampMonotonic Service Scope Leader Class State RootDirectory)' \
165 {-a,--all}'[Show all proerties]' \
166 (-l,--full)'[Do not ellipsize cgroup members]' \
167 '--no-pager[Do not pipe output into a pager]' \
168 '--no-ask-password[Do not ask for system passwords]' \
169 '--kill-who=[Who to send signal to]:killwho:(leader all)' \
170 {-s,--signal=}'[Which signal to send]:signal:_signals' \
171 {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
172 {-P,--privileged}'[Acquire privileges before execution]' \
173 '*::machinectl command:_machinectl_command'
174 ;;
175 *) _message 'eh?' ;;
176 esac
177 }
178
179 _systemd-nspawn(){
180 local -a _caps
181 _caps=( CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH
182 CAP_FOWNER CAP_FSETID CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE
183 CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SETGID CAP_SETFCAP CAP_SETPCAP
184 CAP_SETUID CAP_SYS_ADMIN CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_TTY_CONFIG
185 CAP_SYS_RESOURCE CAP_SYS_BOOT )
186 _values -s , 'capabilities' "$_caps[@]"
187 }
188
189 _systemd_inhibit_command(){
190 if (( CURRENT == 1 )); then
191 compset -q
192 _normal
193 else
194 local n=${words[(b:2:i)[^-]*]}
195 if (( n <= CURRENT )); then
196 compset -n $n
197 _alternative \
198 'files:file:_files' \
199 'commands:command:_normal' && return 0
200 fi
201 _default
202 fi
203
204 }
205
206 _systemd_analyze_command(){
207 local -a _systemd_analyze_cmds
208 # Descriptions taken from systemd-analyze --help.
209 _systemd_analyze_cmds=(
210 'time:Print time spent in the kernel before reaching userspace'
211 'blame:Print list of running units ordered by time to init'
212 'critical-chain:Print a tree of the time critical chain of units'
213 'plot:Output SVG graphic showing service initialization'
214 'dot:Dump dependency graph (in dot(1) format)'
215 )
216
217 if (( CURRENT == 1 )); then
218 _describe "options" _systemd_analyze_cmds
219 else
220 _message "no more options"
221 fi
222 }
223
224 _hosts_or_user_at_host()
225 {
226 _alternative \
227 'users-hosts:: _user_at_host' \
228 'hosts:: _hosts'
229 }
230
231 _outputmodes() {
232 local -a _output_opts
233 _output_opts=(short short-monotonic verbose export json json-pretty json-see cat)
234 _describe -t output 'output mode' _output_opts || compadd "$@"
235 }
236
237 _timedatectl_set-timezone(){
238 local -a _timezones
239 _timezones=( ${(f)"$(_call_program timezones "${service}" list-timezones)"} )
240 compadd "$_timezones[@]"
241 }
242
243 _timedatectl_set-time(){
244 _message "YYYY-MM-DD HH:MM:SS"
245 }
246
247 _timedatectl_set-local-rtc(){
248 local -a _options
249 _options=(
250 '0:Maintain RTC in universal time'
251 '1:Maintain RTC in local time'
252 )
253 _describe options _options
254 }
255
256 _timedatectl_set-ntp(){
257 local -a _options
258 _options=(
259 '0:Disable NTP based network time configuration'
260 '1:Enable NTP based network time configuration'
261 )
262 _describe options _options
263 }
264
265 _timedatectl_command(){
266 local -a _timedatectl_cmds
267 _timedatectl_cmds=(
268 'status:Show current time settings'
269 'set-time:Set system time'
270 'set-timezone:Set system timezone'
271 'list-timezones:Show known timezones'
272 'set-local-rtc:Control whether RTC is in local time'
273 'set-ntp:Control whether NTP is enabled'
274 )
275 if (( CURRENT == 1 )); then
276 _describe -t commands 'timedatectl command' _timedatectl_cmds
277 else
278 local curcontext="$curcontext"
279 cmd="${${_timedatectl_cmds[(r)$words[1]:*]%%:*}}"
280 if (( $#cmd )); then
281 if (( $+functions[_timedatectl_$cmd] )); then
282 _timedatectl_$cmd
283 else
284 _message "no more options"
285 fi
286 else
287 _message "unknown timedatectl command: $words[1]"
288 fi
289 fi
290 }
291 _systemd-coredumpctl_command(){
292 local -a _systemd_coredumpctl_cmds
293 _systemd_coredumpctl_cmds=(
294 'list:List available coredumps'
295 'dump:Print coredump to std'
296 )
297 if (( CURRENT == 1 )); then
298 _describe -t commands 'systemd-coredumpctl command' _systemd_coredumpctl_cmds
299 else
300 local curcontext="$curcontext"
301 local -a _dumps
302 cmd="${${_systemd_coredumpctl_cmds[(r)$words[1]:*]%%:*}}"
303 if (( $#cmd )); then
304 # user can set zstyle ':completion:*:*:systemd-coredumpctl:*' sort no for coredumps to be ordered by date, otherwise they get ordered by pid
305 _dumps=( "${(foa)$(systemd-coredumpctl list | awk 'BEGIN{OFS=":"} /^\s/ {sub(/[[ \t]+/, ""); print $5,$0}' 2>/dev/null)}" )
306 if [[ -n "$_dumps" ]]; then
307 _describe -t pids 'coredumps' _dumps
308 else
309 _message "no coredumps"
310 fi
311 else
312 _message "no more options"
313 fi
314
315 fi
316
317 }
318
319 (( $+functions[_machinectl_command] )) || _machinectl_command()
320 {
321 local -a _machinectl_cmds
322 _machinectl_cmds=(
323 "list:List currently running VMs/containers"
324 "status:Show VM/container status"
325 "show:Show properties of one or more VMs/containers"
326 "terminate:Terminate one or more VMs/containers"
327 "kill:Send signal to process or a VM/container"
328 )
329 if (( CURRENT == 1 )); then
330 _describe -t commands 'machinectl command' _machinectl_cmds || compadd "$@"
331 else
332 local curcontext="$curcontext"
333 cmd="${${_machinectl_cmds[(r)$words[1]:*]%%:*}}"
334 if (( $#cmd )); then
335 case $cmd in
336 list) msg="no options" ;;
337 *)
338 _machines=( "${(foa)$(machinectl list | awk '{print $1}')}" )
339 if [[ -n "$_machines" ]]; then
340 _describe 'machines' _machines
341 else
342 _message 'no machines'
343 fi
344 esac
345 else
346 _message "no more options"
347 fi
348 fi
349 }
350
351 _udevadm_info(){
352 _arguments \
353 '--query=[Query the database for specified type of device data. It needs the --path or --name to identify the specified device.]:type:(name symlink path property all)' \
354 '--path=[The devpath of the device to query.]:sys files:_files -P /sys/ -W /sys' \
355 '--name=[The name of the device node or a symlink to query]:device files:_files -P /dev/ -W /dev' \
356 '--root[Print absolute paths in name or symlink query.]' \
357 '--attribute-walk[Print all sysfs properties of the specified device that can be used in udev rules to match the specified device]' \
358 '--export[Print output as key/value pairs.]' \
359 '--export-prefix=[Add a prefix to the key name of exported values.]:prefix' \
360 '--device-id-of-file=[Print major/minor numbers of the underlying device, where the file lives on.]:files:_udevadm_mounts' \
361 '--export-db[Export the content of the udev database.]' \
362 '--cleanup-db[Cleanup the udev database.]'
363 }
364
365 _udevadm_trigger(){
366 _arguments \
367 '--verbose[Print the list of devices which will be triggered.]' \
368 '--dry-run[Do not actually trigger the event.]' \
369 '--type=[Trigger a specific type of devices.]:types:(devices subsystems failed)' \
370 '--action=[Type of event to be triggered.]:actions:(add change remove)' \
371 '--subsystem-match=[Trigger events for devices which belong to a matching subsystem.]' \
372 '--subsystem-nomatch=[Do not trigger events for devices which belong to a matching subsystem.]' \
373 '--attr-match=attribute=[Trigger events for devices with a matching sysfs attribute.]' \
374 '--attr-nomatch=attribute=[Do not trigger events for devices with a matching sysfs attribute.]' \
375 '--property-match=[Trigger events for devices with a matching property value.]' \
376 '--tag-match=property[Trigger events for devices with a matching tag.]' \
377 '--sysname-match=[Trigger events for devices with a matching sys device name.]' \
378 '--parent-match=[Trigger events for all children of a given device.]'
379 }
380
381 _udevadm_settle(){
382 _arguments \
383 '--timeout=[Maximum number of seconds to wait for the event queue to become empty.]' \
384 '--seq-start=[Wait only for events after the given sequence number.]' \
385 '--seq-end=[Wait only for events before the given sequence number.]' \
386 '--exit-if-exists=[Stop waiting if file exists.]:files:_files' \
387 '--quiet[Do not print any output, like the remaining queue entries when reaching the timeout.]' \
388 '--help[Print help text.]'
389 }
390
391 _udevadm_control(){
392 _arguments \
393 '--exit[Signal and wait for systemd-udevd to exit.]' \
394 '--log-priority=[Set the internal log level of systemd-udevd.]:priorities:(err info debug)' \
395 '--stop-exec-queue[Signal systemd-udevd to stop executing new events. Incoming events will be queued.]' \
396 '--start-exec-queue[Signal systemd-udevd to enable the execution of events.]' \
397 '--reload[Signal systemd-udevd to reload the rules files and other databases like the kernel module index.]' \
398 '--property=[Set a global property for all events.]' \
399 '--children-max=[Set the maximum number of events.]' \
400 '--timeout=[The maximum number of seconds to wait for a reply from systemd-udevd.]' \
401 '--help[Print help text.]'
402 }
403
404 _udevadm_monitor(){
405 _arguments \
406 '--kernel[Print the kernel uevents.]' \
407 '--udev[Print the udev event after the rule processing.]' \
408 '--property[Also print the properties of the event.]' \
409 '--subsystem-match=[Filter events by subsystem/\[devtype\].]' \
410 '--tag-match=[Filter events by property.]' \
411 '--help[Print help text.]'
412 }
413
414 _udevadm_test(){
415 _arguments \
416 '--action=[The action string.]:actions:(add change remove)' \
417 '--subsystem=[The subsystem string.]' \
418 '--help[Print help text.]' \
419 '*::devpath:_files -P /sys/ -W /sys'
420 }
421
422 _udevadm_test-builtin(){
423 if (( CURRENT == 2 )); then
424 _arguments \
425 '--help[Print help text]' \
426 '*::builtins:(blkid btrfs hwdb input_id kmod path_id usb_id uaccess)'
427 elif (( CURRENT == 3 )); then
428 _arguments \
429 '--help[Print help text]' \
430 '*::syspath:_files -P /sys -W /sys'
431 else
432 _arguments \
433 '--help[Print help text]'
434 fi
435 }
436
437 _udevadm_mounts(){
438 local dev_tmp dpath_tmp mp_tmp mline
439
440 tmp=( "${(@f)$(< /etc/mtab)}" )
441 dev_tmp=( "${(@)${(@)tmp%% *}:#none}" )
442 mp_tmp=( "${(@)${(@)tmp#* }%% *}" )
443
444 local MATCH
445 mp_tmp=("${(@q)mp_tmp//(#m)\\[0-7](#c3)/${(#)$(( 8#${MATCH[2,-1]} ))}}")
446 dpath_tmp=( "${(@Mq)dev_tmp:#/*}" )
447 dev_tmp=( "${(@q)dev_tmp:#/*}" )
448
449 _alternative \
450 'device-paths: device path:compadd -a dpath_tmp' \
451 'directories:mount point:compadd -a mp_tmp'
452 }
453
454
455 _udevadm_command(){
456 local -a _udevadm_cmds
457 _udevadm_cmds=(
458 'info:query sysfs or the udev database'
459 'trigger:request events from the kernel'
460 'settle:wait for the event queue to finish'
461 'control:control the udev daemon'
462 'monitor:listen to kernel and udev events'
463 'test:test an event run'
464 'test-builtin:test a built-in command'
465 )
466
467 if ((CURRENT == 1)); then
468 _describe -t commands 'udevadm commands' _udevadm_cmds
469 else
470 local curcontext="$curcontext"
471 cmd="${${_udevadm_cmds[(r)$words[1]:*]%%:*}}"
472 if (($#cmd)); then
473 if (( $+functions[_udevadm_$cmd] )); then
474 _udevadm_$cmd
475 else
476 _message "no options for $cmd"
477 fi
478 else
479 _message "no more options"
480 fi
481 fi
482 }
483
484 _ctls "$@"
485
486 #vim: set ft=zsh sw=4 ts=4 et