_loginctl revision 6da49b8b2f78fd74bb33de961ef8a4c7f727b822
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas#compdef loginctl
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas_loginctl_all_sessions(){_sys_all_sessions=($(loginctl list-sessions | { while read a b; do echo " $a"; done; }) )}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas_loginctl_all_users() {_sys_all_users=( $(loginctl list-users | { while read a b; do echo " $a"; done; }) )}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas_loginctl_all_seats() {_sys_all_seats=( $(loginctl list-seats | { while read a b; do echo " $a"; done; }) )}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
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()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas {
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _loginctl_all_sessions
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas compadd "$@" -a - _sys_all_sessions
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas }
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokasdone
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
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()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas {
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _loginctl_all_users
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas compadd "$@" -a - _sys_all_users
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas }
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokasdone
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# Completion functions for SEATS
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas(( $+functions[_loginctl_seats] )) || _loginctl_seats()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas{
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _loginctl_all_seats
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas compadd "$@" -a - _sys_all_seats
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokasfor fun in seat-status show-seat terminate-seat ; do
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas (( $+functions[_loginctl_$fun] )) || _loginctl_$fun()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas { _loginctl_seats }
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokasdone
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# Completion functions for ATTACH
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas(( $+functions[_loginctl_attach] )) || _loginctl_attach()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas{
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _loginctl_all_seats
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _arguments -w -C -S -s \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas ':seat:_loginctl_seats' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '*:device:_files'
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# no loginctl completion for:
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas# [STANDALONE]='list-sessions list-users list-seats flush-devices'
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas(( $+functions[_loginctl_command] )) || _loginctl_command()
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas{
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"
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 )
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas if (( CURRENT == 1 )); then
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas else
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas local curcontext="$curcontext"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas if (( $#cmd )); then
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas curcontext="${curcontext%:*:*}:loginctl-${cmd}:"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _call_function ret _loginctl_$cmd || _message 'no more arguments'
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas else
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas _message "unknown loginctl command: $words[1]"
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas fi
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas return ret
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas fi
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas}
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas
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' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '--no-ask-password[Do not ask for system passwords]' \
6da49b8b2f78fd74bb33de961ef8a4c7f727b822Zbigniew Jędrzejewski-Szmek {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas {-P,--privileged}'[Acquire privileges before execution]' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '--no-pager[Do not pipe output into a pager]' \
799d54be0b681c0329539fca604261994e7f8c0eWilliam Giokas '*::loginctl command:_loginctl_command'