1 # loginctl(1) completion -*- shell-script -*-
3 # This file is part of systemd.
5 # Copyright 2010 Ran Benita
7 # systemd is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation; either version 2.1 of the License, or
10 # (at your option) any later version.
12 # systemd is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 local w word=$1; shift
23 [[ $w = "$word" ]] && return
27 __get_all_sessions () { loginctl --no-legend list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
28 __get_all_users () { loginctl --no-legend list-users | { while read -r a b; do printf "%s\n" "$b"; done; } ; }
29 __get_all_seats () { loginctl --no-legend list-seats | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
32 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
36 [STANDALONE]='--all -a --help -h --no-pager --privileged -P --version'
37 [ARG]='--host -H --kill-who --property -p --signal -s'
40 if __contains_word "$prev" ${OPTS[ARG]}; then
43 comps=$(compgen -A signal)
49 comps=$(compgen -A hostname)
55 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
60 if [[ "$cur" = -* ]]; then
61 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
66 [SESSIONS]='session-status show-session activate lock-session unlock-session terminate-session kill-session'
67 [USERS]='user-status show-user enable-linger disable-linger terminate-user kill-user'
68 [SEATS]='seat-status show-seat terminate-seat'
69 [STANDALONE]='list-sessions list-users list-seats flush-devices'
73 for ((i=0; i < COMP_CWORD; i++)); do
74 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
75 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
81 if [[ -z $verb ]]; then
84 elif __contains_word "$verb" ${VERBS[SESSIONS]}; then
85 comps=$( __get_all_sessions )
87 elif __contains_word "$verb" ${VERBS[USERS]}; then
88 comps=$( __get_all_users )
90 elif __contains_word "$verb" ${VERBS[SEATS]}; then
91 comps=$( __get_all_seats )
93 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
96 elif __contains_word "$verb" ${VERBS[ATTACH]}; then
97 if [[ $prev = $verb ]]; then
98 comps=$( __get_all_seats )
100 comps=$(compgen -A file -- "$cur" )
105 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
109 complete -F _loginctl loginctl