1 # loginctl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
6 # Copyright 2010 Ran Benita
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 local w word=$1; shift
24 [[ $w = "$word" ]] && return
28 __get_all_sessions () { loginctl --no-legend list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
29 __get_all_users () { loginctl --no-legend list-users | { while read -r a b; do printf "%s\n" "$b"; done; } ; }
30 __get_all_seats () { loginctl --no-legend list-seats | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
33 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
37 [STANDALONE]='--all -a --help -h --no-pager --version
38 --no-legend --no-ask-password -l --full --value'
39 [ARG]='--host -H --kill-who --property -p --signal -s -M --machine
40 -n --lines -o --output'
43 if __contains_word "$prev" ${OPTS[ARG]}; then
53 comps=$(compgen -A hostname)
59 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
64 if [[ "$cur" = -* ]]; then
65 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
70 [SESSIONS]='session-status show-session activate lock-session unlock-session terminate-session kill-session'
71 [USERS]='user-status show-user enable-linger disable-linger terminate-user kill-user'
72 [SEATS]='seat-status show-seat terminate-seat'
73 [STANDALONE]='list-sessions lock-sessions unlock-sessions list-users list-seats flush-devices'
77 for ((i=0; i < COMP_CWORD; i++)); do
78 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
79 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
85 if [[ -z $verb ]]; then
88 elif __contains_word "$verb" ${VERBS[SESSIONS]}; then
89 comps=$( __get_all_sessions )
91 elif __contains_word "$verb" ${VERBS[USERS]}; then
92 comps=$( __get_all_users )
94 elif __contains_word "$verb" ${VERBS[SEATS]}; then
95 comps=$( __get_all_seats )
97 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
100 elif __contains_word "$verb" ${VERBS[ATTACH]}; then
101 if [[ $prev = $verb ]]; then
102 comps=$( __get_all_seats )
104 comps=$(compgen -A file -- "$cur" )
109 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
113 complete -F _loginctl loginctl