]>
Commit | Line | Data |
---|---|---|
682e043c | 1 | #compdef loginctl |
db9ecf05 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
799d54be | 3 | |
c501ecd7 | 4 | (( $+functions[_loginctl_all_sessions] )) || |
b0fe29ff | 5 | _loginctl_all_sessions() { |
843cfcb1 ZJS |
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 | |
b0fe29ff EC |
11 | } |
12 | ||
c501ecd7 | 13 | (( $+functions[_loginctl_all_users] )) || |
b0fe29ff | 14 | _loginctl_all_users() { |
843cfcb1 ZJS |
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 | |
b0fe29ff | 20 | } |
799d54be | 21 | |
c501ecd7 | 22 | (( $+functions[_loginctl_all_seats] )) || |
b0fe29ff | 23 | _loginctl_all_seats() { |
843cfcb1 ZJS |
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 | |
b0fe29ff EC |
29 | } |
30 | ||
31 | local fun | |
799d54be WG |
32 | # Completion functions for SESSIONS |
33 | for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do | |
843cfcb1 ZJS |
34 | (( $+functions[_loginctl_$fun] )) || |
35 | _loginctl_$fun() { | |
b0fe29ff EC |
36 | local -a _sys_all_sessions{,_descr} |
37 | ||
0fb8f025 RP |
38 | _sys_all_sessions=( "self" ) |
39 | _sys_all_sessions_descr=( "self:alias for the current session" ) | |
40 | ||
799d54be | 41 | _loginctl_all_sessions |
b0fe29ff | 42 | for _ignore in $words[2,-1]; do |
843cfcb1 ZJS |
43 | _sys_all_sessions[(i)$_ignore]=() |
44 | _sys_all_sessions_descr[(i)$_ignore:*]=() | |
b0fe29ff EC |
45 | done |
46 | ||
fb9d85b7 | 47 | if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then |
843cfcb1 | 48 | _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@" |
fb9d85b7 | 49 | else |
843cfcb1 ZJS |
50 | local expl |
51 | _wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions | |
fb9d85b7 | 52 | fi |
843cfcb1 | 53 | } |
799d54be WG |
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 | |
843cfcb1 ZJS |
58 | (( $+functions[_loginctl_$fun] )) || |
59 | _loginctl_$fun() { | |
b0fe29ff EC |
60 | local -a _sys_all_users{,_descr} |
61 | zstyle -a ":completion:${curcontext}:users" users _sys_all_users | |
62 | ||
63 | if ! (( $#_sys_all_users )); then | |
843cfcb1 | 64 | _loginctl_all_users |
b0fe29ff EC |
65 | fi |
66 | ||
67 | for _ignore in $words[2,-1]; do | |
843cfcb1 ZJS |
68 | _sys_all_users[(i)$_ignore]=() |
69 | _sys_all_users_descr[(i)$_ignore:*]=() | |
b0fe29ff | 70 | done |
fb9d85b7 | 71 | |
b0fe29ff | 72 | # using the common tag `users' here, not rolling our own `systemd-users' tag |
fb9d85b7 | 73 | if zstyle -T ":completion:${curcontext}:users" verbose; then |
843cfcb1 | 74 | _describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@" |
fb9d85b7 | 75 | else |
843cfcb1 ZJS |
76 | local expl |
77 | _wanted users expl user compadd "$@" -a _sys_all_users | |
fb9d85b7 | 78 | fi |
843cfcb1 | 79 | } |
799d54be WG |
80 | done |
81 | ||
82 | # Completion functions for SEATS | |
843cfcb1 ZJS |
83 | (( $+functions[_loginctl_seats] )) || |
84 | _loginctl_seats() { | |
85 | local -a _sys_all_seats{,_descr} | |
86 | ||
0fb8f025 RP |
87 | _sys_all_seats=( "self" ) |
88 | _sys_all_seats_descr=( "self:alias for the current seat" ) | |
89 | ||
843cfcb1 ZJS |
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 | |
799d54be WG |
102 | } |
103 | for fun in seat-status show-seat terminate-seat ; do | |
843cfcb1 ZJS |
104 | (( $+functions[_loginctl_$fun] )) || |
105 | _loginctl_$fun() { _loginctl_seats } | |
799d54be WG |
106 | done |
107 | ||
108 | # Completion functions for ATTACH | |
843cfcb1 ZJS |
109 | (( $+functions[_loginctl_attach] )) || |
110 | _loginctl_attach() { | |
111 | _arguments -w -C -S -s \ | |
112 | ':seat:_loginctl_seats' \ | |
113 | '*:device:_files' | |
799d54be WG |
114 | } |
115 | ||
116 | # no loginctl completion for: | |
117 | # [STANDALONE]='list-sessions list-users list-seats flush-devices' | |
118 | ||
843cfcb1 ZJS |
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 "$@" | |
799d54be | 150 | else |
843cfcb1 ZJS |
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 | |
799d54be | 163 | fi |
799d54be WG |
164 | } |
165 | ||
166 | ||
167 | _arguments -s \ | |
20927c0e EK |
168 | '(- *)'{-h,--help}'[Show help]' \ |
169 | '(- *)--version[Show package version]' \ | |
170 | '*'{-p+,--property=}'[Show only properties by this name]:unit property' \ | |
171 | '(-a --all)'{-a,--all}'[Show all properties, including empty ones]' \ | |
4ccde410 | 172 | '--kill-whom=[Whom to send signal to]:killwhom:(main control all)' \ |
20927c0e EK |
173 | '(-s --signal)'{-s+,--signal=}'[Which signal to send]:signal:_signals' \ |
174 | '(-H --host)'{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \ | |
175 | '(-M --machine)'{-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \ | |
176 | '(-l --full)'{-l,--full}'[Do not ellipsize output]' \ | |
799d54be | 177 | '--no-pager[Do not pipe output into a pager]' \ |
4433c995 DM |
178 | '--no-legend[Do not show the headers and footers]' \ |
179 | '--no-ask-password[Do not ask for system passwords]' \ | |
20927c0e EK |
180 | '(-n --lines)'{-n+,--lines=}'[Number of journal entries to show]' \ |
181 | '(-o --output)'{-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \ | |
c501ecd7 | 182 | '*::loginctl command:_loginctl_commands' |