2021-06-16 22:35:12 +03:00
#compdef loginctl
2020-11-09 07:23:58 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2013-07-29 23:03:43 +04:00
2018-12-24 14:15:38 +03:00
(( $+functions[_loginctl_all_sessions] )) ||
2015-06-17 14:41:24 +03:00
_loginctl_all_sessions() {
2019-04-05 12:39:14 +03:00
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
2015-06-17 14:41:24 +03:00
}
2018-12-24 14:15:38 +03:00
(( $+functions[_loginctl_all_users] )) ||
2015-06-17 14:41:24 +03:00
_loginctl_all_users() {
2019-04-05 12:39:14 +03:00
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
2015-06-17 14:41:24 +03:00
}
2013-07-29 23:03:43 +04:00
2018-12-24 14:15:38 +03:00
(( $+functions[_loginctl_all_seats] )) ||
2015-06-17 14:41:24 +03:00
_loginctl_all_seats() {
2019-04-05 12:39:14 +03:00
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
2015-06-17 14:41:24 +03:00
}
local fun
2013-07-29 23:03:43 +04:00
# Completion functions for SESSIONS
for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
2019-04-05 12:39:14 +03:00
(( $+functions[_loginctl_$fun] )) ||
_loginctl_$fun() {
2015-06-17 14:41:24 +03:00
local -a _sys_all_sessions{,_descr}
2020-09-30 10:11:48 +03:00
_sys_all_sessions=( "self" )
_sys_all_sessions_descr=( "self:alias for the current session" )
2013-07-29 23:03:43 +04:00
_loginctl_all_sessions
2015-06-17 14:41:24 +03:00
for _ignore in $words[2,-1]; do
2019-04-05 12:39:14 +03:00
_sys_all_sessions[(i)$_ignore]=()
_sys_all_sessions_descr[(i)$_ignore:*]=()
2015-06-17 14:41:24 +03:00
done
2015-06-23 01:07:32 +03:00
if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then
2019-04-05 12:39:14 +03:00
_describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
2015-06-23 01:07:32 +03:00
else
2019-04-05 12:39:14 +03:00
local expl
_wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions
2015-06-23 01:07:32 +03:00
fi
2019-04-05 12:39:14 +03:00
}
2013-07-29 23:03:43 +04:00
done
# Completion functions for USERS
for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
2019-04-05 12:39:14 +03:00
(( $+functions[_loginctl_$fun] )) ||
_loginctl_$fun() {
2015-06-17 14:41:24 +03:00
local -a _sys_all_users{,_descr}
zstyle -a ":completion:${curcontext}:users" users _sys_all_users
if ! (( $#_sys_all_users )); then
2019-04-05 12:39:14 +03:00
_loginctl_all_users
2015-06-17 14:41:24 +03:00
fi
for _ignore in $words[2,-1]; do
2019-04-05 12:39:14 +03:00
_sys_all_users[(i)$_ignore]=()
_sys_all_users_descr[(i)$_ignore:*]=()
2015-06-17 14:41:24 +03:00
done
2015-06-23 01:07:32 +03:00
2015-06-17 14:41:24 +03:00
# using the common tag `users' here, not rolling our own `systemd-users' tag
2015-06-23 01:07:32 +03:00
if zstyle -T ":completion:${curcontext}:users" verbose; then
2019-04-05 12:39:14 +03:00
_describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@"
2015-06-23 01:07:32 +03:00
else
2019-04-05 12:39:14 +03:00
local expl
_wanted users expl user compadd "$@" -a _sys_all_users
2015-06-23 01:07:32 +03:00
fi
2019-04-05 12:39:14 +03:00
}
2013-07-29 23:03:43 +04:00
done
# Completion functions for SEATS
2019-04-05 12:39:14 +03:00
(( $+functions[_loginctl_seats] )) ||
_loginctl_seats() {
local -a _sys_all_seats{,_descr}
2020-09-30 10:11:48 +03:00
_sys_all_seats=( "self" )
_sys_all_seats_descr=( "self:alias for the current seat" )
2019-04-05 12:39:14 +03:00
_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
2013-07-29 23:03:43 +04:00
}
for fun in seat-status show-seat terminate-seat ; do
2019-04-05 12:39:14 +03:00
(( $+functions[_loginctl_$fun] )) ||
_loginctl_$fun() { _loginctl_seats }
2013-07-29 23:03:43 +04:00
done
# Completion functions for ATTACH
2019-04-05 12:39:14 +03:00
(( $+functions[_loginctl_attach] )) ||
_loginctl_attach() {
_arguments -w -C -S -s \
':seat:_loginctl_seats' \
'*:device:_files'
2013-07-29 23:03:43 +04:00
}
# no loginctl completion for:
# [STANDALONE]='list-sessions list-users list-seats flush-devices'
2019-04-05 12:39:14 +03:00
(( $+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 "$@"
2013-07-29 23:03:43 +04:00
else
2019-04-05 12:39:14 +03:00
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
2013-07-29 23:03:43 +04:00
fi
}
_arguments -s \
{-h,--help}'[Show help]' \
'--version[Show package version]' \
2013-08-21 07:06:54 +04:00
\*{-p+,--property=}'[Show only properties by this name]:unit property' \
2013-07-29 23:03:43 +04:00
{-a,--all}'[Show all properties, including empty ones]' \
'--kill-who=[Who to send signal to]:killwho:(main control all)' \
2013-08-21 07:06:54 +04:00
{-s+,--signal=}'[Which signal to send]:signal:_signals' \
2013-12-01 07:31:31 +04:00
{-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
2015-04-07 20:35:13 +03:00
{-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \
2014-03-25 23:28:31 +04:00
{-l,--full}'[Do not ellipsize output]' \
2013-07-29 23:03:43 +04:00
'--no-pager[Do not pipe output into a pager]' \
2014-03-25 23:28:31 +04:00
'--no-legend[Do not show the headers and footers]' \
'--no-ask-password[Do not ask for system passwords]' \
2015-04-07 20:35:13 +03:00
{-n+,--lines=}'[Number of journal entries to show]' \
{-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
2018-12-24 14:15:38 +03:00
'*::loginctl command:_loginctl_commands'