d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# localectl(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 () {
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner local w word=$1; shift
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner for w in "$@"; do
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner [[ $w = "$word" ]] && return
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek__locale_fields=( LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME \
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER \
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek LC_NAME LC_ADDRESS LC_TELEPHONE \
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek LC_MEASUREMENT LC_IDENTIFICATION )
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek# LC_ALL is omitted on purpose
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl_localectl() {
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek local i verb comps locale_vals
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
b4f91f2ba354c16dc23111cc231010c975c717a2Carlos Morata Castillo -H --host --machine'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "$prev" $OPTS; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl case $prev in
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 [STANDALONE]='status list-locales list-keymaps'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [LOCALES]='set-locale'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [KEYMAPS]='set-keymap'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [X11]='set-x11-keymap'
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 if [[ -z $verb ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=${VERBS[*]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[LOCALES]}; then
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek if [[ $cur = *=* ]]; then
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "${cur#=}") )
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek elif [[ $prev = "=" ]]; then
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "$cur") )
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek compopt -o nospace
627a98d39844a1ac10fde1f72cf18b4f08be4990Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '${__locale_fields[*]}' -S= -- "$cur") )
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 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Bieblcomplete -F _localectl localectl