localectl revision 3ce09b7da2eb8b888066468663b2b5c81a05a03c
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# localectl(1) completion -*- shell-script -*-
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# This file is part of systemd.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# Copyright 2010 Ran Benita
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
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#
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#
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
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__contains_word () {
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner local w word=$1; shift
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner for w in "$@"; do
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner [[ $w = "$word" ]] && return
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner done
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl_localectl() {
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local i verb comps
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local OPTS='-h --help --version --no-convert --no-pager --no-ask-password
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl -H --host'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "$prev" $OPTS; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl case $prev in
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --host|-H)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=''
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl esac
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ $cur = -* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local -A VERBS=(
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [STANDALONE]='status list-locales list-keymaps'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [LOCALES]='set-locale'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [KEYMAPS]='set-keymap'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [X11]='set-x11-keymap'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
3ce09b7da2eb8b888066468663b2b5c81a05a03cZbigniew Jędrzejewski-Szmek for ((i=0; i < COMP_CWORD; i++)); do
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl verb=${COMP_WORDS[i]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl break
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl done
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ -z $verb ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=${VERBS[*]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[LOCALES]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(command localectl list-locales)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[KEYMAPS]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(command localectl list-keymaps)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[X11]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=''
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Bieblcomplete -F _localectl localectl