1 # localectl(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 __locale_fields=( LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME \
29 LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER \
30 LC_NAME LC_ADDRESS LC_TELEPHONE \
31 LC_MEASUREMENT LC_IDENTIFICATION )
32 # LC_ALL is omitted on purpose
35 local i verb comps locale_vals
36 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
37 local OPTS='-h --help --version --no-convert --no-pager --no-ask-password
38 -H --host -M --machine'
40 if __contains_word "$prev" $OPTS; then
46 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
50 if [[ $cur = -* ]]; then
51 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
56 [STANDALONE]='status list-locales list-keymaps list-x11-keymap-models list-x11-keymap-layouts list-x11-keymap-options'
57 [VARIANTS]='list-x11-keymap-variants'
58 [LOCALES]='set-locale'
59 [KEYMAPS]='set-keymap'
60 [X11]='set-x11-keymap'
63 for ((i=0; i < COMP_CWORD; i++)); do
64 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
70 if [[ -z $verb ]]; then
72 elif __contains_word "$verb" ${VERBS[VARIANTS]}; then
73 comps=$(command localectl list-x11-keymap-layouts)
74 elif __contains_word "$verb" ${VERBS[LOCALES]}; then
75 if [[ $cur = *=* ]]; then
76 mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
77 COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "${cur#=}") )
78 elif [[ $prev = "=" ]]; then
79 mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
80 COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "$cur") )
83 COMPREPLY=( $(compgen -W '${__locale_fields[*]}' -S= -- "$cur") )
86 elif __contains_word "$verb" ${VERBS[KEYMAPS]}; then
87 comps=$(command localectl list-keymaps)
88 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[X11]}; then
92 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
96 complete -F _localectl localectl