chiark / gitweb /
78cb0611813794fcbf11da5dc7d6feba8a3d0099
[elogind.git] / shell-completion / zsh / _systemd
1 #compdef 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-analyze)
8             _arguments \
9                 {-h,--help}'[Show help text.]' \
10                 '--user[Shows performance data of user sessions instead of the system manager.]' \
11                 '--order[When generating graph for dot, show only order]' \
12                 '--require[When generating graph for dot, show only requirement]' \
13                 '*::systemd-analyze commands:_systemd_analyze_command'
14         ;;
15         systemd-ask-password)
16             _arguments \
17                 {-h,--help}'[Show this help]' \
18                 '--icon=[Icon name]' \
19                 '--timeout=[Timeout in sec]' \
20                 '--no-tty[Ask question via agent even on TTY]' \
21                 '--accept-cached[Accept cached passwords]' \
22                 '--multiple[List multiple passwords if available]'
23         ;;
24         systemd-cat)
25             _arguments \
26                 {-h,--help}'[Show this help]' \
27                 '--version[Show package version.]' \
28                 {-t,--identifier=}'[Set syslog identifier.]' \
29                 {-p,--priority=}'[Set priority value.]:value:({0..7})' \
30                 '--level-prefix=[Control whether level prefix shall be parsed.]:boolean:(1 0)' \
31                 ':Message'
32         ;;
33         systemd-cgls)
34             _arguments \
35                 {-h,--help}'[Show this help]' \
36                 '--version[Show package version]' \
37                 '--no-pager[Do not pipe output into a pager]' \
38                 {-a,--all}'[Show all groups, including empty]' \
39                 '-k[Include kernel threads in output]' \
40                 ':cgroups:(cpuset cpu cpuacct memory devices freezer net_cls blkio)'
41         ;;
42         systemd-cgtop)
43             _arguments \
44                 {-h,--help}'[Show this help]' \
45                 '--version[Print version and exit]' \
46                 '(-c -m -i -t)-p[Order by path]' \
47                 '(-c -p -m -i)-t[Order by number of tasks]' \
48                 '(-m -p -i -t)-c[Order by CPU load]' \
49                 '(-c -p -i -t)-m[Order by memory load]' \
50                 '(-c -m -p -t)-i[Order by IO load]' \
51                 {-d,--delay=}'[Specify delay]' \
52                 {-n,--iterations=}'[Run for N iterations before exiting]' \
53                 {-b,--batch}'[Run in batch mode, accepting no input]' \
54                 '--depth=[Maximum traversal depth]'
55         ;;
56         systemd-delta)
57             _arguments \
58                 {-h,--help}'[Show this help]' \
59                 '--version[Show package version]' \
60                 '--no-pager[Do not pipe output into a pager]' \
61                 '--diff=[Show a diff when overridden files differ]:boolean:(1 0)' \
62                 {-t,--type=}'[Only display a selected set of override types]:types:(masked equivalent redirected overridden unchanged)' \
63                 ':SUFFIX:(tmpfiles.d sysctl.d systemd/system)'
64         ;;
65         systemd-detect-virt)
66             _arguments \
67                 {-h,--help}'[Show this help]' \
68                 '--version[Show package version]' \
69                 {-c,--container}'[Only detect whether we are run in a container]' \
70                 {-v,--vm}'[Only detect whether we are run in a VM]' \
71                 {-q,--quiet}"[Don't output anything, just set return value]"
72         ;;
73         systemd-inhibit)
74             _arguments \
75                 {-h,--help}'[Show this help]' \
76                 '--version[Show package version]' \
77                 '--what=[Operations to inhibit]:options:(shutdown sleep idle handle-power-key handle-suspend-key handle-hibernate-key handle-lid-switch)' \
78                 '--who=[A descriptive string who is inhibiting]' \
79                 '--why=[A descriptive string why is being inhibited]' \
80                 '--mode=[One of block or delay]' \
81                 '--list[List active inhibitors]' \
82                 '*:commands:_systemd_inhibit_command'
83         ;;
84         systemd-machine-id-setup)
85             _arguments \
86                 {-h,--help}'[Show this help]' \
87                 '--version[Show package version]'
88         ;;
89         systemd-notify)
90             _arguments \
91                 {-h,--help}'[Show this help]' \
92                 '--version[Show package version]' \
93                 '--ready[Inform the init system about service start-up completion.]' \
94                 '--pid=[Inform the init system about the main PID of the daemon]' \
95                 '--status=[Send a free-form status string for the daemon to the init systemd]' \
96                 '--booted[Returns 0 if the system was booted up with systemd]' \
97                 '--readahead=[Controls disk read-ahead operations]:arguments:(cancel done noreply)'
98         ;;
99         systemd-nspawn)
100             _arguments \
101                 {-h,--help}'[Show this help]' \
102                 {--directory=,-D}'[Directory to use as file system root for the namespace container. If omitted the current directory will be used.]:directories:_directories' \
103                 {--boot,-b}'[Automatically search for an init binary and invoke it instead of a shell or a user supplied program.]' \
104                 {--user=,-u}'[Run the command under specified user, create home directory and cd into it.]' \
105                 '--uuid=[Set the specified uuid for the container.]' \
106                 {--controllers=,-C}'[Makes the container appear in other hierarchies than the name=systemd:/ one. Takes a comma-separated list of controllers.]' \
107                 '--private-network[Turn off networking in the container. This makes all network interfaces unavailable in the container, with the exception of the loopback device.]' \
108                 '--read-only[Mount the root file system read only for the container.]' \
109                 '--capability=[List one or more additional capabilities to grant the container.]:capabilities:_systemd-nspawn' \
110                 "--link-journal=[Control whether the container's journal shall be made visible to the host system.]:options:(no, host, guest, auto)" \
111                 '-j[Equivalent to --link-journal=guest.]'
112         ;;
113         systemd-tmpfiles)
114             _arguments \
115                 '--create[Create, set ownership/permissions based on the config files.]' \
116                 '--clean[Clean up all files and directories with an age parameter configured.]' \
117                 '--remove[All files and directories marked with r, R in the configuration files are removed.]' \
118                 '--prefix=[Only apply rules that apply to paths with the specified prefix.]' \
119                 '--exclude-prefix=[Ignore rules that apply to paths with the specified prefix.]' \
120                 '--help[Prints a short help text and exits.]' \
121                 '*::files:_files'
122         ;;
123         systemd-tty-ask-password-agent)
124             _arguments \
125                 {-h,--help}'[Prints a short help text and exits.]' \
126                 '--version[Prints a short version string and exits.]' \
127                 '--list[Lists all currently pending system password requests.]' \
128                 '--query[Process all currently pending system password requests by querying the user on the calling TTY.]' \
129                 '--watch[Continuously process password requests.]' \
130                 '--wall[Forward password requests to wall(1).]' \
131                 '--plymouth[Ask question with plymouth(8).]' \
132                 '--console[Ask question on /dev/console.]'
133         ;;
134         machinectl)
135             _arguments \
136                 {-h,--help}'[Prints a short help text and exits.]' \
137                 '--version[Prints a short version string and exits.]' \
138                 {-p,--property=}'[Limit output to specified property.]:property:(Name Id Timestamp TimestampMonotonic Service Scope Leader Class State RootDirectory)' \
139                 {-a,--all}'[Show all proerties]' \
140                 (-l,--full)'[Do not ellipsize cgroup members]' \
141                 '--no-pager[Do not pipe output into a pager]' \
142                 '--no-ask-password[Do not ask for system passwords]' \
143                 '--kill-who=[Who to send signal to]:killwho:(leader all)' \
144                 {-s,--signal=}'[Which signal to send]:signal:_signals' \
145                 {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
146                 {-P,--privileged}'[Acquire privileges before execution]' \
147                 '*::machinectl command:_machinectl_command'
148         ;;
149         *) _message 'eh?' ;;
150     esac
151 }
152
153 _systemd-nspawn(){
154     local -a _caps
155     _caps=( CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH
156             CAP_FOWNER CAP_FSETID CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE
157             CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SETGID CAP_SETFCAP CAP_SETPCAP
158             CAP_SETUID CAP_SYS_ADMIN CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_TTY_CONFIG
159             CAP_SYS_RESOURCE CAP_SYS_BOOT )
160     _values -s , 'capabilities' "$_caps[@]"
161 }
162
163 _systemd_inhibit_command(){
164     if (( CURRENT == 1 )); then
165         compset -q
166         _normal
167     else
168         local n=${words[(b:2:i)[^-]*]}
169         if (( n <= CURRENT )); then
170             compset -n $n
171             _alternative \
172                 'files:file:_files' \
173                 'commands:command:_normal' && return 0
174         fi
175         _default
176     fi
177
178 }
179
180 _systemd_analyze_command(){
181     local -a _systemd_analyze_cmds
182     # Descriptions taken from systemd-analyze --help.
183     _systemd_analyze_cmds=(
184         'time:Print time spent in the kernel before reaching userspace'
185         'blame:Print list of running units ordered by time to init'
186         'critical-chain:Print a tree of the time critical chain of units'
187         'plot:Output SVG graphic showing service initialization'
188         'dot:Dump dependency graph (in dot(1) format)'
189     )
190
191     if (( CURRENT == 1 )); then
192         _describe "options" _systemd_analyze_cmds
193     else
194         _message "no more options"
195     fi
196 }
197
198 _hosts_or_user_at_host()
199 {
200   _alternative \
201     'users-hosts:: _user_at_host' \
202     'hosts:: _hosts'
203 }
204
205 _outputmodes() {
206     local -a _output_opts
207     _output_opts=(short short-monotonic verbose export json json-pretty json-see cat)
208     _describe -t output 'output mode' _output_opts || compadd "$@"
209 }
210
211 (( $+functions[_machinectl_command] )) || _machinectl_command()
212 {
213   local -a _machinectl_cmds
214   _machinectl_cmds=(
215     "list:List currently running VMs/containers"
216     "status:Show VM/container status"
217     "show:Show properties of one or more VMs/containers"
218     "terminate:Terminate one or more VMs/containers"
219     "kill:Send signal to process or a VM/container"
220   )
221   if (( CURRENT == 1 )); then
222     _describe -t commands 'machinectl command' _machinectl_cmds || compadd "$@"
223   else
224     local curcontext="$curcontext"
225     cmd="${${_machinectl_cmds[(r)$words[1]:*]%%:*}}"
226     if (( $#cmd )); then
227       case $cmd in
228         list) msg="no options" ;;
229         *)
230           _machines=( "${(foa)$(machinectl list | awk '{print $1}')}" )
231           if [[ -n "$_machines" ]]; then
232             _describe 'machines' _machines
233           else
234             _message 'no machines'
235           fi
236       esac
237     else
238       _message "no more options"
239     fi
240   fi
241 }
242
243 _ctls "$@"
244
245 #vim: set ft=zsh sw=4 ts=4 et