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