[systemd-devel] [PATCH 2/2] Use local -A OPTS in all bash autocompletions

Carlos Morata Castillo cmc809 at inlumine.ual.es
Sat Jan 10 04:54:17 PST 2015


Hi,

For homogenisation,  we should use an associative array in "all" the bash autocompletion scripts, thus when someone added new options should type
them into the correct type. 


My intention is to make bash script completions homogeneous in order to maintain them more efficiently.


PD: Sorry for the new thread, my mailbox is not working properly and can't get my owns Cc: into inbox.

---
 shell-completion/bash/coredumpctl | 7 +++++--
 shell-completion/bash/hostnamectl | 6 ++++--
 shell-completion/bash/localectl   | 8 +++++---
 shell-completion/bash/systemd-run | 9 ++++++---
 shell-completion/bash/timedatectl | 8 +++++---
 shell-completion/bash/udevadm     | 5 ++++-
 6 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/shell-completion/bash/coredumpctl b/shell-completion/bash/coredumpctl
index 0c4cda3..83b3084 100644
--- a/shell-completion/bash/coredumpctl
+++ b/shell-completion/bash/coredumpctl
@@ -34,7 +34,10 @@ __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
 _coredumpctl() {
         local i verb comps
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-        local OPTS='-h --help --version --no-pager --no-legend -o --output -F --field'
+        local -A OPTS=(
+               [STANDALONE]='-h --help --version --no-pager --no-legend -1'
+                      [ARG]='-o --output -F --field'
+        )
 
         local -A VERBS=(
             [LIST]='list'
@@ -47,7 +50,7 @@ _coredumpctl() {
         elif __systemdh_contains_word "$prev" '--FIELD -F'; then
                 comps=$( compgen -W '${__journal_fields[*]}' -- "$cur" )
         elif [[ $cur = -* ]]; then
-                comps=${OPTS}
+                comps=${OPTS[*]}
         elif __systemdh_contains_word "$prev" ${VERBS[*]} &&
            ! __systemdh_contains_word ${COMP_WORDS[COMP_CWORD-2]} '--output -o -F --field'; then
                 compopt -o nospace
diff --git a/shell-completion/bash/hostnamectl b/shell-completion/bash/hostnamectl
index a74931f..c01f6ce 100644
--- a/shell-completion/bash/hostnamectl
+++ b/shell-completion/bash/hostnamectl
@@ -23,8 +23,10 @@
 _hostnamectl() {
         local i verb comps
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-        local OPTS='-h --help --version --transient --static --pretty
-                    --no-ask-password -H --host'
+        local -A OPTS=(
+               [STANDALONE]='-h --help --version --transient --static --pretty --no-ask-password'
+                      [ARG]='-H --host'
+        )
 
         if [[ $cur = -* ]]; then
                 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
diff --git a/shell-completion/bash/localectl b/shell-completion/bash/localectl
index 647ff89..acd543c 100644
--- a/shell-completion/bash/localectl
+++ b/shell-completion/bash/localectl
@@ -29,10 +29,12 @@ __locale_fields=( LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME \
 _localectl() {
         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'
+        local -A OPTS=(
+               [STANDALONE]='-h --help --version --no-convert --no-pager --no-ask-password'
+                      [ARG]='-H --host'
+        )
 
-        if __systemdh_contains_word "$prev" $OPTS; then
+        if __systemdh_contains_word "$prev" ${OPTS[ARG]}; then
                 case $prev in
                         --host|-H)
                                 comps=''
diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run
index f459760..f71f841 100644
--- a/shell-completion/bash/systemd-run
+++ b/shell-completion/bash/systemd-run
@@ -22,9 +22,12 @@
 
 _systemd_run() {
     local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-    local OPTS='-h --help --version --user --system --scope --unit --description --slice
-        -r --remain-after-exit --send-sighup -H --host -M --machine --service-type
-        --uid --gid --nice --setenv -p --property'
+        local -A OPTS=(
+               [STANDALONE]='-h --help --version --user --system --scope -r
+               --remain-after-exit --send-sigup '
+                      [ARG]='--unit --description --slice -H --host -M --machine 
+                      --service-type --uid --gid --nice --setenv -p --property'
+        )
 
         local mode=--system
         local i
diff --git a/shell-completion/bash/timedatectl b/shell-completion/bash/timedatectl
index e07661d..cb8bd92 100644
--- a/shell-completion/bash/timedatectl
+++ b/shell-completion/bash/timedatectl
@@ -23,10 +23,12 @@
 _timedatectl() {
         local i verb comps
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-        local OPTS='-h --help --version --adjust-system-clock --no-pager
-                    --no-ask-password -H --host'
+        local -A OPTS=(
+               [STANDALONE]='-h --help --version --no-pager --no-ask-password --adjust-system-clock'
+                      [ARG]='-H --host'
+        )
 
-        if __systemdh_contains_word "$prev" $OPTS; then
+        if __systemdh_contains_word "$prev" ${OPTS[ARG]}; then
                 case $prev in
                         --host|-H)
                                 comps=''
diff --git a/shell-completion/bash/udevadm b/shell-completion/bash/udevadm
index b24b7be..7326d1a 100644
--- a/shell-completion/bash/udevadm
+++ b/shell-completion/bash/udevadm
@@ -24,7 +24,10 @@
 _udevadm() {
         local i verb comps
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-        local OPTS='-h --help --version --debug'
+        local -A OPTS=(
+               [STANDALONE]='-h --help --version --debug'
+                      [ARG]=''
+        )
 
         local verbs=(info trigger settle control monitor hwdb test-builtin test)
 
-- 
2.1.0



More information about the systemd-devel mailing list