2 # SPDX-License-Identifier: LGPL-2.1+
4 _loginctl_all_sessions() {
5 local session description
6 loginctl --no-legend list-sessions | while read -r session description; do
7 _sys_all_sessions+=( "$session" )
8 _sys_all_sessions_descr+=( "${session}:$description" )
12 _loginctl_all_users() {
14 loginctl --no-legend list-users | while read -r uid description; do
15 _sys_all_users+=( "$uid" )
16 _sys_all_users_descr+=( "${uid}:$description" )
20 _loginctl_all_seats() {
21 local seat description
22 loginctl --no-legend list-seats | while read -r seat description; do
23 _sys_all_seats+=( "$seat" )
24 _sys_all_seats_descr+=( "${seat}:$description" )
29 # Completion functions for SESSIONS
30 for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
31 (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
33 local -a _sys_all_sessions{,_descr}
35 _loginctl_all_sessions
36 for _ignore in $words[2,-1]; do
37 _sys_all_sessions[(i)$_ignore]=()
38 _sys_all_sessions_descr[(i)$_ignore:*]=()
41 if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then
42 _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
45 _wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions
50 # Completion functions for USERS
51 for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
52 (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
54 local -a _sys_all_users{,_descr}
55 zstyle -a ":completion:${curcontext}:users" users _sys_all_users
57 if ! (( $#_sys_all_users )); then
61 for _ignore in $words[2,-1]; do
62 _sys_all_users[(i)$_ignore]=()
63 _sys_all_users_descr[(i)$_ignore:*]=()
66 # using the common tag `users' here, not rolling our own `systemd-users' tag
67 if zstyle -T ":completion:${curcontext}:users" verbose; then
68 _describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@"
71 _wanted users expl user compadd "$@" -a _sys_all_users
76 # Completion functions for SEATS
77 (( $+functions[_loginctl_seats] )) || _loginctl_seats()
79 local -a _sys_all_seats{,_descr}
82 for _ignore in $words[2,-1]; do
83 _sys_all_seats[(i)$_ignore]=()
84 _sys_all_seats_descr[(i)$_ignore:*]=()
87 if zstyle -T ":completion:${curcontext}:systemd-seats" verbose; then
88 _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@"
91 _wanted systemd-seats expl seat compadd "$@" -a _sys_all_seats
94 for fun in seat-status show-seat terminate-seat ; do
95 (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
99 # Completion functions for ATTACH
100 (( $+functions[_loginctl_attach] )) || _loginctl_attach()
102 _arguments -w -C -S -s \
103 ':seat:_loginctl_seats' \
107 # no loginctl completion for:
108 # [STANDALONE]='list-sessions list-users list-seats flush-devices'
110 (( $+functions[_loginctl_command] )) || _loginctl_command()
112 local -a _loginctl_cmds
114 "list-sessions:List sessions"
115 "session-status:Show session status"
116 "show-session:Show properties of one or more sessions"
117 "activate:Activate a session"
118 "lock-session:Screen lock one or more sessions"
119 "unlock-session:Screen unlock one or more sessions"
120 "lock-sessions:Screen lock all current sessions"
121 "unlock-sessions:Screen unlock all current sessions"
122 "terminate-session:Terminate one or more sessions"
123 "kill-session:Send signal to processes of a session"
124 "list-users:List users"
125 "user-status:Show user status"
126 "show-user:Show properties of one or more users"
127 "enable-linger:Enable linger state of one or more users"
128 "disable-linger:Disable linger state of one or more users"
129 "terminate-user:Terminate all sessions of one or more users"
130 "kill-user:Send signal to processes of a user"
131 "list-seats:List seats"
132 "seat-status:Show seat status"
133 "show-seat:Show properties of one or more seats"
134 "attach:Attach one or more devices to a seat"
135 "flush-devices:Flush all device associations"
136 "terminate-seat:Terminate all sessions on one or more seats"
139 if (( CURRENT == 1 )); then
140 _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
142 local curcontext="$curcontext" _ignore
144 cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
147 curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
149 _call_function ret _loginctl_$cmd || _message 'no more arguments'
151 _message "unknown loginctl command: $words[1]"
159 {-h,--help}'[Show help]' \
160 '--version[Show package version]' \
161 \*{-p+,--property=}'[Show only properties by this name]:unit property' \
162 {-a,--all}'[Show all properties, including empty ones]' \
163 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
164 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
165 {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
166 {-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \
167 {-l,--full}'[Do not ellipsize output]' \
168 '--no-pager[Do not pipe output into a pager]' \
169 '--no-legend[Do not show the headers and footers]' \
170 '--no-ask-password[Do not ask for system passwords]' \
171 {-n+,--lines=}'[Number of journal entries to show]' \
172 {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
173 '*::loginctl command:_loginctl_command'