loginctl revision d611dadcc74db10ba533ee6859308f5fc505aee1
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# loginctl(1) completion -*- shell-script -*-
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# This file is part of systemd.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# Copyright 2010 Ran Benita
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# systemd is free software; you can redistribute it and/or modify it
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# under the terms of the GNU Lesser General Public License as published by
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# the Free Software Foundation; either version 2.1 of the License, or
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# (at your option) any later version.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# systemd is distributed in the hope that it will be useful, but
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# WITHOUT ANY WARRANTY; without even the implied warranty of
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# General Public License for more details.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# You should have received a copy of the GNU Lesser General Public License
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# along with systemd; If not, see <http://www.gnu.org/licenses/>.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__contains_word () {
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local word=$1; shift
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl for w in $*; do [[ $w = $word ]] && return 0; done
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__get_all_sessions () { loginctl list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__get_all_users () { loginctl list-users | { while read -r a b; do printf "%s\n" "$b"; done; } ; }
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__get_all_seats () { loginctl list-seats | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl_loginctl () {
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local i verb comps
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local -A OPTS=(
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [STANDALONE]='--all -a --help -h --no-pager --privileged -P --version'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [ARG]='--host -H --kill-who --property -p --signal -s'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "$prev" ${OPTS[ARG]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl case $prev in
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(compgen -A signal)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps='all leader'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(compgen -A hostname)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --property|-p)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ "$cur" = -* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local -A VERBS=(
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [SESSIONS]='session-status show-session activate lock-session unlock-session terminate-session kill-session'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [USERS]='user-status show-user enable-linger disable-linger terminate-user kill-user'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [SEATS]='seat-status show-seat terminate-seat'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [STANDALONE]='list-sessions list-users list-seats flush-devices'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [ATTACH]='attach'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl for ((i=0; $i <= $COMP_CWORD; i++)); do
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl verb=${COMP_WORDS[i]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ -z $verb ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps="${VERBS[*]}"
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[SESSIONS]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$( __get_all_sessions )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[USERS]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$( __get_all_users )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[SEATS]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$( __get_all_seats )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[ATTACH]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ $prev = $verb ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$( __get_all_seats )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(compgen -A file -- "$cur" )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl compopt -o filenames
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Bieblcomplete -F _loginctl loginctl