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