]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/zsh/_loginctl
Merge pull request #247 from shaded-enmity/origin/pullfix
[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 _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
41 }
42 done
43
44 # Completion functions for USERS
45 for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
46 (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
47 {
48 local -a _sys_all_users{,_descr}
49 zstyle -a ":completion:${curcontext}:users" users _sys_all_users
50
51 if ! (( $#_sys_all_users )); then
52 _loginctl_all_users
53 fi
54
55 for _ignore in $words[2,-1]; do
56 _sys_all_users[(i)$_ignore]=()
57 _sys_all_users_descr[(i)$_ignore:*]=()
58 done
59 # using the common tag `users' here, not rolling our own `systemd-users' tag
60 _describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@"
61 }
62 done
63
64 # Completion functions for SEATS
65 (( $+functions[_loginctl_seats] )) || _loginctl_seats()
66 {
67 local -a _sys_all_seats{,_descr}
68
69 _loginctl_all_seats
70 for _ignore in $words[2,-1]; do
71 _sys_all_seats[(i)$_ignore]=()
72 _sys_all_seats_descr[(i)$_ignore:*]=()
73 done
74
75 _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@"
76 }
77 for fun in seat-status show-seat terminate-seat ; do
78 (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
79 { _loginctl_seats }
80 done
81
82 # Completion functions for ATTACH
83 (( $+functions[_loginctl_attach] )) || _loginctl_attach()
84 {
85 _arguments -w -C -S -s \
86 ':seat:_loginctl_seats' \
87 '*:device:_files'
88 }
89
90 # no loginctl completion for:
91 # [STANDALONE]='list-sessions list-users list-seats flush-devices'
92
93 (( $+functions[_loginctl_command] )) || _loginctl_command()
94 {
95 local -a _loginctl_cmds
96 _loginctl_cmds=(
97 "list-sessions:List sessions"
98 "session-status:Show session status"
99 "show-session:Show properties of one or more sessions"
100 "activate:Activate a session"
101 "lock-session:Screen lock one or more sessions"
102 "unlock-session:Screen unlock one or more sessions"
103 "lock-sessions:Screen lock all current sessions"
104 "unlock-sessions:Screen unlock all current sessions"
105 "terminate-session:Terminate one or more sessions"
106 "kill-session:Send signal to processes of a session"
107 "list-users:List users"
108 "user-status:Show user status"
109 "show-user:Show properties of one or more users"
110 "enable-linger:Enable linger state of one or more users"
111 "disable-linger:Disable linger state of one or more users"
112 "terminate-user:Terminate all sessions of one or more users"
113 "kill-user:Send signal to processes of a user"
114 "list-seats:List seats"
115 "seat-status:Show seat status"
116 "show-seat:Show properties of one or more seats"
117 "attach:Attach one or more devices to a seat"
118 "flush-devices:Flush all device associations"
119 "terminate-seat:Terminate all sessions on one or more seats"
120 )
121
122 if (( CURRENT == 1 )); then
123 _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
124 else
125 local curcontext="$curcontext" _ignore
126
127 cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
128
129 if (( $#cmd )); then
130 curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
131
132 _call_function ret _loginctl_$cmd || _message 'no more arguments'
133 else
134 _message "unknown loginctl command: $words[1]"
135 fi
136 return ret
137 fi
138 }
139
140
141 _arguments -s \
142 {-h,--help}'[Show help]' \
143 '--version[Show package version]' \
144 \*{-p+,--property=}'[Show only properties by this name]:unit property' \
145 {-a,--all}'[Show all properties, including empty ones]' \
146 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
147 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
148 {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
149 {-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \
150 {-l,--full}'[Do not ellipsize output]' \
151 '--no-pager[Do not pipe output into a pager]' \
152 '--no-legend[Do not show the headers and footers]' \
153 '--no-ask-password[Do not ask for system passwords]' \
154 {-n+,--lines=}'[Number of journal entries to show]' \
155 {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
156 '*::loginctl command:_loginctl_command'