1 # This file is part of systemd.
3 # Copyright 2010 Ran Benita
5 # systemd is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) any later version.
10 # systemd is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 for w in $*; do [[ $w = $word ]] && return 0; done
24 __get_all_sessions () { loginctl list-sessions | { while read -r a b; do echo " $a"; done; } ; }
25 __get_all_users () { loginctl list-users | { while read -r a b; do echo " $b"; done; } ; }
26 __get_all_seats () { loginctl list-seats | { while read -r a b; do echo " $a"; done; } ; }
29 local i verb comps cur prev
30 _get_comp_words_by_ref cur prev
32 local OPTS_STANDALONE='--all -a --help -h --no-pager --privileged -P --version'
33 local OPTS_ARG='--host -H --kill-who --property -p --signal -s'
35 if __contains_word "$prev" "$OPTS_ARG"; then
38 comps=$(compgen -A signal)
44 comps=$(compgen -A hostname)
50 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
54 if [[ "$cur" = -* ]]; then
55 COMPREPLY=( $(compgen -W '$OPTS_ARG $OPTS_STANDALONE' -- "$cur") )
59 local VERBS_SESSIONS='session-status show-session activate lock-session unlock-session terminate-session kill-session'
60 local VERBS_USERS='user-status show-user enable-linger disable-linger terminate-user kill-user'
61 local VERBS_SEATS='seat-status show-seat terminate-seat'
62 local VERBS_STANDALONE='list-sessions list-users list-seats flush-devices'
63 local VERBS_ATTACH='attach'
64 local VERBS="$VERBS_SESSIONS $VERBS_USERS $VERBS_SEATS $VERBS_STANDALONE $VERBS_ATTACH"
67 for ((i=0; $i <= $COMP_CWORD; i++)); do
68 if __contains_word "${COMP_WORDS[i]}" "$VERBS" &&
69 ! __contains_word "${COMP_WORDS[i-1]}" "$OPTS_ARG"; then
75 if [[ -z $verb ]]; then
78 elif __contains_word "$verb" "$VERBS_SESSIONS"; then
79 comps=$( __get_all_sessions )
81 elif __contains_word "$verb" "$VERBS_USERS"; then
82 comps=$( __get_all_users )
84 elif __contains_word "$verb" "$VERBS_SEATS"; then
85 comps=$( __get_all_seats )
87 elif __contains_word "$verb" "$VERBS_STANDALONE"; then
90 elif __contains_word "$verb" $VERBS_ATTACH; then
91 if [[ $prev = $verb ]]; then
92 comps=$( __get_all_seats )
94 comps=$(compgen -o filenames -A file -- "$cur" )
98 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
101 complete -F _loginctl loginctl