1 #compdef loginctl -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1-or-later
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" )
13 (( $+functions[_loginctl_all_users] )) ||
14 _loginctl_all_users() {
16 loginctl --no-legend list-users | while read -r uid description; do
17 _sys_all_users+=( "$uid" )
18 _sys_all_users_descr+=( "${uid}:$description" )
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" )
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] )) ||
36 local -a _sys_all_sessions{,_descr}
38 _sys_all_sessions=( "self" )
39 _sys_all_sessions_descr=( "self:alias for the current session" )
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:*]=()
47 if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then
48 _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
51 _wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions
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] )) ||
60 local -a _sys_all_users{,_descr}
61 zstyle -a ":completion:${curcontext}:users" users _sys_all_users
63 if ! (( $#_sys_all_users )); then
67 for _ignore in $words[2,-1]; do
68 _sys_all_users[(i)$_ignore]=()
69 _sys_all_users_descr[(i)$_ignore:*]=()
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 "$@"
77 _wanted users expl user compadd "$@" -a _sys_all_users
82 # Completion functions for SEATS
83 (( $+functions[_loginctl_seats] )) ||
85 local -a _sys_all_seats{,_descr}
87 _sys_all_seats=( "self" )
88 _sys_all_seats_descr=( "self:alias for the current seat" )
91 for _ignore in $words[2,-1]; do
92 _sys_all_seats[(i)$_ignore]=()
93 _sys_all_seats_descr[(i)$_ignore:*]=()
96 if zstyle -T ":completion:${curcontext}:systemd-seats" verbose; then
97 _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@"
100 _wanted systemd-seats expl seat compadd "$@" -a _sys_all_seats
103 for fun in seat-status show-seat terminate-seat ; do
104 (( $+functions[_loginctl_$fun] )) ||
105 _loginctl_$fun() { _loginctl_seats }
108 # Completion functions for ATTACH
109 (( $+functions[_loginctl_attach] )) ||
111 _arguments -w -C -S -s \
112 ':seat:_loginctl_seats' \
116 # no loginctl completion for:
117 # [STANDALONE]='list-sessions list-users list-seats flush-devices'
119 (( $+functions[_loginctl_commands] )) ||
120 _loginctl_commands() {
121 local -a _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"
148 if (( CURRENT == 1 )); then
149 _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
151 local curcontext="$curcontext" _ignore
153 cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
156 curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
158 _call_function ret _loginctl_$cmd || _message 'no more arguments'
160 _message "unknown loginctl command: $words[1]"
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'