chiark / gitweb /
man: add a link to systemd-coredump(8) in Description of coredump.conf(5)
[elogind.git] / shell-completion / bash / localectl
index bec9e78..c9e22af 100644 (file)
@@ -24,8 +24,14 @@ __contains_word () {
         done
 }
 
+__locale_fields=( LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME \
+                  LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER \
+                  LC_NAME LC_ADDRESS LC_TELEPHONE \
+                  LC_MEASUREMENT LC_IDENTIFICATION )
+# LC_ALL is omitted on purpose
+
 _localectl() {
-        local i verb comps
+        local i verb comps locale_vals
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
         local OPTS='-h --help --version --no-convert --no-pager --no-ask-password
                     -H --host'
@@ -52,7 +58,7 @@ _localectl() {
                       [X11]='set-x11-keymap'
         )
 
-        for ((i=0; i <= COMP_CWORD; i++)); do
+        for ((i=0; i < COMP_CWORD; i++)); do
                 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
                         verb=${COMP_WORDS[i]}
                         break
@@ -62,7 +68,17 @@ _localectl() {
         if [[ -z $verb ]]; then
                 comps=${VERBS[*]}
         elif __contains_word "$verb" ${VERBS[LOCALES]}; then
-                comps=$(command localectl list-locales)
+                if [[ $cur = *=* ]]; then
+                        mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
+                        COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "${cur#=}") )
+                elif [[ $prev = "=" ]]; then
+                        mapfile -t locale_vals < <(command localectl list-locales 2>/dev/null)
+                        COMPREPLY=( $(compgen -W '${locale_vals[*]}' -- "$cur") )
+                else
+                        compopt -o nospace
+                        COMPREPLY=( $(compgen -W '${__locale_fields[*]}' -S= -- "$cur") )
+                fi
+                return 0
         elif __contains_word "$verb" ${VERBS[KEYMAPS]}; then
                 comps=$(command localectl list-keymaps)
         elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[X11]}; then