799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas#compdef loginctl
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook_loginctl_all_sessions() {
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook local session description
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook loginctl --no-legend list-sessions | while read -r session description; do
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_sessions+=( "$session" )
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_sessions_descr+=( "${session}:$description" )
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook_loginctl_all_users() {
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook local uid description
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook loginctl --no-legend list-users | while read -r uid description; do
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_users+=( "$uid" )
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_users_descr+=( "${uid}:$description" )
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook_loginctl_all_seats() {
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook local seat description
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook loginctl --no-legend list-seats | while read -r seat description; do
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_seats+=( "$seat" )
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_seats_descr+=( "${seat}:$description" )
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# Completion functions for SESSIONS
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokasfor fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook local -a _sys_all_sessions{,_descr}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _loginctl_all_sessions
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook for _ignore in $words[2,-1]; do
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_sessions[(i)$_ignore]=()
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_sessions_descr[(i)$_ignore:*]=()
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook if zstyle -T ":completion:${curcontext}:systemd-sessions" verbose; then
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@"
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook _wanted systemd-sessions expl session compadd "$@" -a _sys_all_sessions
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# Completion functions for USERS
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokasfor fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook local -a _sys_all_users{,_descr}
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook zstyle -a ":completion:${curcontext}:users" users _sys_all_users
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook if ! (( $#_sys_all_users )); then
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _loginctl_all_users
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook for _ignore in $words[2,-1]; do
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_users[(i)$_ignore]=()
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_users_descr[(i)$_ignore:*]=()
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook # using the common tag `users' here, not rolling our own `systemd-users' tag
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook if zstyle -T ":completion:${curcontext}:users" verbose; then
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook _describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@"
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook _wanted users expl user compadd "$@" -a _sys_all_users
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# Completion functions for SEATS
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas(( $+functions[_loginctl_seats] )) || _loginctl_seats()
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook local -a _sys_all_seats{,_descr}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _loginctl_all_seats
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook for _ignore in $words[2,-1]; do
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_seats[(i)$_ignore]=()
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook _sys_all_seats_descr[(i)$_ignore:*]=()
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook if zstyle -T ":completion:${curcontext}:systemd-seats" verbose; then
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@"
fb9d85b71ac1a9247af623f98f4e229fccd0fe7dEric Cook _wanted systemd-seats expl seat compadd "$@" -a _sys_all_seats
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokasfor fun in seat-status show-seat terminate-seat ; do
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas { _loginctl_seats }
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# Completion functions for ATTACH
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas(( $+functions[_loginctl_attach] )) || _loginctl_attach()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _arguments -w -C -S -s \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas ':seat:_loginctl_seats' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '*:device:_files'
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# no loginctl completion for:
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# [STANDALONE]='list-sessions list-users list-seats flush-devices'
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas(( $+functions[_loginctl_command] )) || _loginctl_command()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas local -a _loginctl_cmds
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _loginctl_cmds=(
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "list-sessions:List sessions"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "session-status:Show session status"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "show-session:Show properties of one or more sessions"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "activate:Activate a session"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "lock-session:Screen lock one or more sessions"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "unlock-session:Screen unlock one or more sessions"
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack "lock-sessions:Screen lock all current sessions"
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack "unlock-sessions:Screen unlock all current sessions"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "terminate-session:Terminate one or more sessions"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "kill-session:Send signal to processes of a session"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "list-users:List users"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "user-status:Show user status"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "show-user:Show properties of one or more users"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "enable-linger:Enable linger state of one or more users"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "disable-linger:Disable linger state of one or more users"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "terminate-user:Terminate all sessions of one or more users"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "kill-user:Send signal to processes of a user"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "list-seats:List seats"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "seat-status:Show seat status"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "show-seat:Show properties of one or more seats"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "attach:Attach one or more devices to a seat"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "flush-devices:Flush all device associations"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas "terminate-seat:Terminate all sessions on one or more seats"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas if (( CURRENT == 1 )); then
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
b0fe29ff9e04d02d939ffca0b942cfb2a3494171Eric Cook local curcontext="$curcontext" _ignore
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas if (( $#cmd )); then
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _call_function ret _loginctl_$cmd || _message 'no more arguments'
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _message "unknown loginctl command: $words[1]"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas_arguments -s \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas {-h,--help}'[Show help]' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '--version[Show package version]' \
862f4963c6f7778cea9e715eeb11ea959eba6db3William Giokas \*{-p+,--property=}'[Show only properties by this name]:unit property' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas {-a,--all}'[Show all properties, including empty ones]' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '--kill-who=[Who to send signal to]:killwho:(main control all)' \
862f4963c6f7778cea9e715eeb11ea959eba6db3William Giokas {-s+,--signal=}'[Which signal to send]:signal:_signals' \
6da49b8b2f78fd74bb33de961ef8a4c7f727b822Zbigniew Jędrzejewski-Szmek {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
8470025541039f39391815b2ac93952003b7eee8Ronny Chevalier {-M+,--machine=}'[Operate on local container]:machine:_sd_machines' \
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack {-l,--full}'[Do not ellipsize output]' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '--no-pager[Do not pipe output into a pager]' \
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack '--no-legend[Do not show the headers and footers]' \
4433c995c77b66f42fe4a238aff6b53706628a2eDaniel Mack '--no-ask-password[Do not ask for system passwords]' \
8470025541039f39391815b2ac93952003b7eee8Ronny Chevalier {-n+,--lines=}'[Number of journal entries to show]' \
8470025541039f39391815b2ac93952003b7eee8Ronny Chevalier {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '*::loginctl command:_loginctl_command'