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