chiark / gitweb /
zsh_completion: Split out zsh _journalctl
[elogind.git] / shell-completion / zsh / _loginctl
1 #compdef loginctl
2
3 _hosts_or_user_at_host() {
4   _alternative \
5     'users-hosts:: _user_at_host' \
6     'hosts:: _hosts'
7 }
8
9 _loginctl_all_sessions(){_sys_all_sessions=($(loginctl list-sessions | { while read a b; do echo " $a"; done; }) )}
10 _loginctl_all_users()   {_sys_all_users=(   $(loginctl list-users    | { while read a b; do echo " $a"; done; }) )}
11 _loginctl_all_seats()   {_sys_all_seats=(   $(loginctl list-seats    | { while read a b; do echo " $a"; done; }) )}
12
13 # Completion functions for SESSIONS
14 for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
15   (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
16   {
17     _loginctl_all_sessions
18     compadd "$@" -a - _sys_all_sessions
19   }
20 done
21
22 # Completion functions for USERS
23 for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
24   (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
25   {
26     _loginctl_all_users
27     compadd "$@" -a - _sys_all_users
28   }
29 done
30
31 # Completion functions for SEATS
32 (( $+functions[_loginctl_seats] )) || _loginctl_seats()
33 {
34   _loginctl_all_seats
35   compadd "$@" -a - _sys_all_seats
36 }
37 for fun in seat-status show-seat terminate-seat ; do
38   (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
39   { _loginctl_seats }
40 done
41
42 # Completion functions for ATTACH
43 (( $+functions[_loginctl_attach] )) || _loginctl_attach()
44 {
45   _loginctl_all_seats
46
47   _arguments -w -C -S -s \
48     ':seat:_loginctl_seats' \
49     '*:device:_files'
50 }
51
52 # no loginctl completion for:
53 # [STANDALONE]='list-sessions list-users list-seats flush-devices'
54
55 (( $+functions[_loginctl_command] )) || _loginctl_command()
56 {
57   local -a _loginctl_cmds
58   _loginctl_cmds=(
59     "list-sessions:List sessions"
60     "session-status:Show session status"
61     "show-session:Show properties of one or more sessions"
62     "activate:Activate a session"
63     "lock-session:Screen lock one or more sessions"
64     "unlock-session:Screen unlock one or more sessions"
65     "terminate-session:Terminate one or more sessions"
66     "kill-session:Send signal to processes of a session"
67     "list-users:List users"
68     "user-status:Show user status"
69     "show-user:Show properties of one or more users"
70     "enable-linger:Enable linger state of one or more users"
71     "disable-linger:Disable linger state of one or more users"
72     "terminate-user:Terminate all sessions of one or more users"
73     "kill-user:Send signal to processes of a user"
74     "list-seats:List seats"
75     "seat-status:Show seat status"
76     "show-seat:Show properties of one or more seats"
77     "attach:Attach one or more devices to a seat"
78     "flush-devices:Flush all device associations"
79     "terminate-seat:Terminate all sessions on one or more seats"
80   )
81
82   if (( CURRENT == 1 )); then
83     _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
84   else
85     local curcontext="$curcontext"
86
87     cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
88
89     if (( $#cmd )); then
90       curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
91
92       _call_function ret _loginctl_$cmd || _message 'no more arguments'
93     else
94       _message "unknown loginctl command: $words[1]"
95     fi
96     return ret
97   fi
98 }
99
100
101 _arguments -s \
102     {-h,--help}'[Show help]' \
103     '--version[Show package version]' \
104     \*{-p,--property=}'[Show only properties by this name]:unit property' \
105     {-a,--all}'[Show all properties, including empty ones]' \
106     '--kill-who=[Who to send signal to]:killwho:(main control all)' \
107     {-s,--signal=}'[Which signal to send]:signal:_signals' \
108     '--no-ask-password[Do not ask for system passwords]' \
109     {-H,--host=}'[Show information for remote host]:userathost:_hosts_or_user_at_host' \
110     {-P,--privileged}'[Acquire privileges before execution]' \
111     '--no-pager[Do not pipe output into a pager]' \
112     '*::loginctl command:_loginctl_command'