]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/zsh/_loginctl
Merge pull request #9853 from poettering/uneeded-queue
[thirdparty/systemd.git] / shell-completion / zsh / _loginctl
1 #compdef loginctl
2 # SPDX-License-Identifier: LGPL-2.1+
3
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" )
9 done
10 }
11
12 _loginctl_all_users() {
13 local uid description
14 loginctl --no-legend list-users | while read -r uid description; do
15 _sys_all_users+=( "$uid" )
16 _sys_all_users_descr+=( "${uid}:$description" )
17 done
18 }
19
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" )
25 done
26 }
27
28 local fun
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()
32 {
33 local -a _sys_all_sessions{,_descr}
34
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:*]=()
39 done
40
41 if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then
42 _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
43 else
44 local expl
45 _wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions
46 fi
47 }
48 done
49
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()
53 {
54 local -a _sys_all_users{,_descr}
55 zstyle -a ":completion:${curcontext}:users" users _sys_all_users
56
57 if ! (( $#_sys_all_users )); then
58 _loginctl_all_users
59 fi
60
61 for _ignore in $words[2,-1]; do
62 _sys_all_users[(i)$_ignore]=()
63 _sys_all_users_descr[(i)$_ignore:*]=()
64 done
65
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 "$@"
69 else
70 local expl
71 _wanted users expl user compadd "$@" -a _sys_all_users
72 fi
73 }
74 done
75
76 # Completion functions for SEATS
77 (( $+functions[_loginctl_seats] )) || _loginctl_seats()
78 {
79 local -a _sys_all_seats{,_descr}
80
81 _loginctl_all_seats
82 for _ignore in $words[2,-1]; do
83 _sys_all_seats[(i)$_ignore]=()
84 _sys_all_seats_descr[(i)$_ignore:*]=()
85 done
86
87 if zstyle -T ":completion:${curcontext}:systemd-seats" verbose; then
88 _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@"
89 else
90 local expl
91 _wanted systemd-seats expl seat compadd "$@" -a _sys_all_seats
92 fi
93 }
94 for fun in seat-status show-seat terminate-seat ; do
95 (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
96 { _loginctl_seats }
97 done
98
99 # Completion functions for ATTACH
100 (( $+functions[_loginctl_attach] )) || _loginctl_attach()
101 {
102 _arguments -w -C -S -s \
103 ':seat:_loginctl_seats' \
104 '*:device:_files'
105 }
106
107 # no loginctl completion for:
108 # [STANDALONE]='list-sessions list-users list-seats flush-devices'
109
110 (( $+functions[_loginctl_command] )) || _loginctl_command()
111 {
112 local -a _loginctl_cmds
113 _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"
137 )
138
139 if (( CURRENT == 1 )); then
140 _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
141 else
142 local curcontext="$curcontext" _ignore
143
144 cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
145
146 if (( $#cmd )); then
147 curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
148
149 _call_function ret _loginctl_$cmd || _message 'no more arguments'
150 else
151 _message "unknown loginctl command: $words[1]"
152 fi
153 return ret
154 fi
155 }
156
157
158 _arguments -s \
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'