]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/localectl
man: Remove OSConfig project mentioning for systemd-confext
[thirdparty/systemd.git] / shell-completion / bash / localectl
CommitLineData
f8457290 1# shellcheck shell=bash
d611dadc 2# localectl(1) completion -*- shell-script -*-
db9ecf05 3# SPDX-License-Identifier: LGPL-2.1-or-later
d611dadc
MB
4#
5# This file is part of systemd.
6#
96b2fb93 7# Copyright © 2010 Ran Benita
d611dadc
MB
8#
9# systemd is free software; you can redistribute it and/or modify it
10# under the terms of the GNU Lesser General Public License as published by
11# the Free Software Foundation; either version 2.1 of the License, or
12# (at your option) any later version.
13#
14# systemd is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public License
85fce6f4 20# along with systemd; If not, see <https://www.gnu.org/licenses/>.
d611dadc
MB
21
22__contains_word () {
843cfcb1
ZJS
23 local w word=$1; shift
24 for w in "$@"; do
25 [[ $w = "$word" ]] && return
26 done
d611dadc
MB
27}
28
843cfcb1
ZJS
29__locale_fields=( LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME
30 LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER
31 LC_NAME LC_ADDRESS LC_TELEPHONE
627a98d3
ZJS
32 LC_MEASUREMENT LC_IDENTIFICATION )
33# LC_ALL is omitted on purpose
34
d611dadc 35_localectl() {
843cfcb1
ZJS
36 local i verb comps locale_vals
37 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
38 local OPTS='-h --help --version --no-convert --no-pager --no-ask-password
f822279e 39 -H --host -M --machine'
d611dadc 40
843cfcb1
ZJS
41 if __contains_word "$prev" $OPTS; then
42 case $prev in
43 --host|-H)
44 comps=''
45 ;;
46 esac
47 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
48 return 0
49 fi
d611dadc 50
843cfcb1
ZJS
51 if [[ $cur = -* ]]; then
52 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
53 return 0
54 fi
d611dadc 55
843cfcb1
ZJS
56 local -A VERBS=(
57 [STANDALONE]='status list-locales list-keymaps list-x11-keymap-models list-x11-keymap-layouts list-x11-keymap-options'
58 [VARIANTS]='list-x11-keymap-variants'
59 [LOCALES]='set-locale'
60 [KEYMAPS]='set-keymap'
61 [X11]='set-x11-keymap'
62 )
d611dadc 63
843cfcb1
ZJS
64 for ((i=0; i < COMP_CWORD; i++)); do
65 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
66 verb=${COMP_WORDS[i]}
67 break
d611dadc 68 fi
843cfcb1 69 done
d611dadc 70
36ec0268 71 if [[ -z ${verb-} ]]; then
843cfcb1
ZJS
72 comps=${VERBS[*]}
73 elif __contains_word "$verb" ${VERBS[VARIANTS]}; then
74 comps=$(command localectl list-x11-keymap-layouts)
75 elif __contains_word "$verb" ${VERBS[LOCALES]}; then
76 if [[ $cur = *=* ]]; then
77 mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
78 COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "${cur#=}") )
79 elif [[ $prev = "=" ]]; then
80 mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
81 COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "$cur") )
82 else
83 compopt -o nospace
84 COMPREPLY=( $(compgen -W '${__locale_fields[*]}' -S= -- "$cur") )
85 fi
d611dadc 86 return 0
843cfcb1
ZJS
87 elif __contains_word "$verb" ${VERBS[KEYMAPS]}; then
88 comps=$(command localectl list-keymaps)
89 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[X11]}; then
90 comps=''
91 fi
92
93 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
94 return 0
d611dadc
MB
95}
96
97complete -F _localectl localectl