summaryrefslogtreecommitdiffstats
path: root/shell-completion/zsh/_loginctl
blob: 44d6d08c9885f54c2a028e40a3ed7dcabe89d26b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#compdef loginctl
# SPDX-License-Identifier: LGPL-2.1+

(( $+functions[_loginctl_all_sessions] )) ||
_loginctl_all_sessions() {
  local session description
  loginctl --no-legend list-sessions | while read -r session description; do
    _sys_all_sessions+=( "$session" )
    _sys_all_sessions_descr+=( "${session}:$description" )
  done
}

(( $+functions[_loginctl_all_users] )) ||
_loginctl_all_users() {
  local uid description
  loginctl --no-legend list-users | while read -r uid description; do
    _sys_all_users+=( "$uid" )
    _sys_all_users_descr+=( "${uid}:$description" )
  done
}

(( $+functions[_loginctl_all_seats] )) ||
_loginctl_all_seats() {
  local seat description
  loginctl --no-legend list-seats | while read -r seat description; do
    _sys_all_seats+=( "$seat" )
    _sys_all_seats_descr+=( "${seat}:$description" )
  done
}

local fun
# Completion functions for SESSIONS
for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
  (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
  {
    local -a _sys_all_sessions{,_descr}

    _loginctl_all_sessions
    for _ignore in $words[2,-1]; do
      _sys_all_sessions[(i)$_ignore]=()
      _sys_all_sessions_descr[(i)$_ignore:*]=()
    done

    if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then
      _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
    else
      local expl
      _wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions
    fi
  }
done

# Completion functions for USERS
for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
  (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
  {
    local -a _sys_all_users{,_descr}
    zstyle -a ":completion:${curcontext}:users" users _sys_all_users

    if ! (( $#_sys_all_users )); then
      _loginctl_all_users
    fi

    for _ignore in $words[2,-1]; do
      _sys_all_users[(i)$_ignore]=()
      _sys_all_users_descr[(i)$_ignore:*]=()
    done

    # using the common tag `users' here, not rolling our own `systemd-users' tag
    if zstyle -T ":completion:${curcontext}:users" verbose; then
      _describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@"
    else
      local expl
      _wanted users expl user compadd "$@" -a _sys_all_users
    fi
  }
done

# Completion functions for SEATS
(( $+functions[_loginctl_seats] )) || _loginctl_seats()
{
  local -a _sys_all_seats{,_descr}

  _loginctl_all_seats
  for _ignore in $words[2,-1]; do
    _sys_all_seats[(i)$_ignore]=()
    _sys_all_seats_descr[(i)$_ignore:*]=()
  done

  if zstyle -T ":completion:${curcontext}:systemd-seats" verbose; then
    _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@"
  else
    local expl
    _wanted systemd-seats expl seat compadd "$@" -a _sys_all_seats
  fi
}
for fun in seat-status show-seat terminate-seat ; do
  (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
  { _loginctl_seats }
done

# Completion functions for ATTACH
(( $+functions[_loginctl_attach] )) || _loginctl_attach()
{
  _arguments -w -C -S -s \
    ':seat:_loginctl_seats' \
    '*:device:_files'
}

# no loginctl completion for:
# [STANDALONE]='list-sessions list-users list-seats flush-devices'

(( $+functions[_loginctl_commands] )) || _loginctl_commands()
{
  local -a _loginctl_cmds
  _loginctl_cmds=(
    "list-sessions:List sessions"
    "session-status:Show session status"
    "show-session:Show properties of one or more sessions"
    "activate:Activate a session"
    "lock-session:Screen lock one or more sessions"
    "unlock-session:Screen unlock one or more sessions"
    "lock-sessions:Screen lock all current sessions"
    "unlock-sessions:Screen unlock all current sessions"
    "terminate-session:Terminate one or more sessions"
    "kill-session:Send signal to processes of a session"
    "list-users:List users"
    "user-status:Show user status"
    "show-user:Show properties of one or more users"
    "enable-linger:Enable linger state of one or more users"
    "disable-linger:Disable linger state of one or more users"
    "terminate-user:Terminate all sessions of one or more users"
    "kill-user:Send signal to processes of a user"
    "list-seats:List seats"
    "seat-status:Show seat status"
    "show-seat:Show properties of one or more seats"
    "attach:Attach one or more devices to a seat"
    "flush-devices:Flush all device associations"
    "terminate-seat:Terminate all sessions on one or more seats"
  )

  if (( CURRENT == 1 )); then
    _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
  else
    local curcontext="$curcontext" _ignore

    cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"

    if (( $#cmd )); then
      curcontext="${curcontext%:*:*}:loginctl-${cmd}:"

      _call_function ret _loginctl_$cmd || _message 'no more arguments'
    else
      _message "unknown loginctl command: $words[1]"
    fi
    return ret
  fi
}


_arguments -s \
    {-h,--help}'[Show help]' \
    '--version[Show package version]' \
    \*{-p+,--property=}'[Show only properties by this name]:unit property' \
    {-a,--all}'[Show all properties, including empty ones]' \
    '--kill-who=[Who to send signal to]:killwho:(main control all)' \
    {-s+,--signal=}'[Which signal to send]:signal:_signals' \
    {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
    {-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \
    {-l,--full}'[Do not ellipsize output]' \
    '--no-pager[Do not pipe output into a pager]' \
    '--no-legend[Do not show the headers and footers]' \
    '--no-ask-password[Do not ask for system passwords]' \
    {-n+,--lines=}'[Number of journal entries to show]' \
    {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
    '*::loginctl command:_loginctl_commands'