]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/zsh/_loginctl
shell-completion/zsh: add -*type*- headers
[thirdparty/systemd.git] / shell-completion / zsh / _loginctl
1 #compdef loginctl -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3
4 (( $+functions[_loginctl_all_sessions] )) ||
5 _loginctl_all_sessions() {
6 local session description
7 loginctl --no-legend list-sessions | while read -r session description; do
8 _sys_all_sessions+=( "$session" )
9 _sys_all_sessions_descr+=( "${session}:$description" )
10 done
11 }
12
13 (( $+functions[_loginctl_all_users] )) ||
14 _loginctl_all_users() {
15 local uid description
16 loginctl --no-legend list-users | while read -r uid description; do
17 _sys_all_users+=( "$uid" )
18 _sys_all_users_descr+=( "${uid}:$description" )
19 done
20 }
21
22 (( $+functions[_loginctl_all_seats] )) ||
23 _loginctl_all_seats() {
24 local seat description
25 loginctl --no-legend list-seats | while read -r seat description; do
26 _sys_all_seats+=( "$seat" )
27 _sys_all_seats_descr+=( "${seat}:$description" )
28 done
29 }
30
31 local fun
32 # Completion functions for SESSIONS
33 for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
34 (( $+functions[_loginctl_$fun] )) ||
35 _loginctl_$fun() {
36 local -a _sys_all_sessions{,_descr}
37
38 _loginctl_all_sessions
39 for _ignore in $words[2,-1]; do
40 _sys_all_sessions[(i)$_ignore]=()
41 _sys_all_sessions_descr[(i)$_ignore:*]=()
42 done
43
44 if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then
45 _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
46 else
47 local expl
48 _wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions
49 fi
50 }
51 done
52
53 # Completion functions for USERS
54 for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
55 (( $+functions[_loginctl_$fun] )) ||
56 _loginctl_$fun() {
57 local -a _sys_all_users{,_descr}
58 zstyle -a ":completion:${curcontext}:users" users _sys_all_users
59
60 if ! (( $#_sys_all_users )); then
61 _loginctl_all_users
62 fi
63
64 for _ignore in $words[2,-1]; do
65 _sys_all_users[(i)$_ignore]=()
66 _sys_all_users_descr[(i)$_ignore:*]=()
67 done
68
69 # using the common tag `users' here, not rolling our own `systemd-users' tag
70 if zstyle -T ":completion:${curcontext}:users" verbose; then
71 _describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@"
72 else
73 local expl
74 _wanted users expl user compadd "$@" -a _sys_all_users
75 fi
76 }
77 done
78
79 # Completion functions for SEATS
80 (( $+functions[_loginctl_seats] )) ||
81 _loginctl_seats() {
82 local -a _sys_all_seats{,_descr}
83
84 _loginctl_all_seats
85 for _ignore in $words[2,-1]; do
86 _sys_all_seats[(i)$_ignore]=()
87 _sys_all_seats_descr[(i)$_ignore:*]=()
88 done
89
90 if zstyle -T ":completion:${curcontext}:systemd-seats" verbose; then
91 _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@"
92 else
93 local expl
94 _wanted systemd-seats expl seat compadd "$@" -a _sys_all_seats
95 fi
96 }
97 for fun in seat-status show-seat terminate-seat ; do
98 (( $+functions[_loginctl_$fun] )) ||
99 _loginctl_$fun() { _loginctl_seats }
100 done
101
102 # Completion functions for ATTACH
103 (( $+functions[_loginctl_attach] )) ||
104 _loginctl_attach() {
105 _arguments -w -C -S -s \
106 ':seat:_loginctl_seats' \
107 '*:device:_files'
108 }
109
110 # no loginctl completion for:
111 # [STANDALONE]='list-sessions list-users list-seats flush-devices'
112
113 (( $+functions[_loginctl_commands] )) ||
114 _loginctl_commands() {
115 local -a _loginctl_cmds
116 _loginctl_cmds=(
117 "list-sessions:List sessions"
118 "session-status:Show session status"
119 "show-session:Show properties of one or more sessions"
120 "activate:Activate a session"
121 "lock-session:Screen lock one or more sessions"
122 "unlock-session:Screen unlock one or more sessions"
123 "lock-sessions:Screen lock all current sessions"
124 "unlock-sessions:Screen unlock all current sessions"
125 "terminate-session:Terminate one or more sessions"
126 "kill-session:Send signal to processes of a session"
127 "list-users:List users"
128 "user-status:Show user status"
129 "show-user:Show properties of one or more users"
130 "enable-linger:Enable linger state of one or more users"
131 "disable-linger:Disable linger state of one or more users"
132 "terminate-user:Terminate all sessions of one or more users"
133 "kill-user:Send signal to processes of a user"
134 "list-seats:List seats"
135 "seat-status:Show seat status"
136 "show-seat:Show properties of one or more seats"
137 "attach:Attach one or more devices to a seat"
138 "flush-devices:Flush all device associations"
139 "terminate-seat:Terminate all sessions on one or more seats"
140 )
141
142 if (( CURRENT == 1 )); then
143 _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
144 else
145 local curcontext="$curcontext" _ignore
146
147 cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
148
149 if (( $#cmd )); then
150 curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
151
152 _call_function ret _loginctl_$cmd || _message 'no more arguments'
153 else
154 _message "unknown loginctl command: $words[1]"
155 fi
156 return ret
157 fi
158 }
159
160
161 _arguments -s \
162 {-h,--help}'[Show help]' \
163 '--version[Show package version]' \
164 \*{-p+,--property=}'[Show only properties by this name]:unit property' \
165 {-a,--all}'[Show all properties, including empty ones]' \
166 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
167 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
168 {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
169 {-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \
170 {-l,--full}'[Do not ellipsize output]' \
171 '--no-pager[Do not pipe output into a pager]' \
172 '--no-legend[Do not show the headers and footers]' \
173 '--no-ask-password[Do not ask for system passwords]' \
174 {-n+,--lines=}'[Number of journal entries to show]' \
175 {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
176 '*::loginctl command:_loginctl_commands'