[systemd-commits] 2 commits - bash-completion/systemd-bash-completion.sh

Dave Reisner dreisner at kemper.freedesktop.org
Sat Oct 20 14:55:59 PDT 2012


 bash-completion/systemd-bash-completion.sh |   43 ++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 4 deletions(-)

New commits:
commit a632a03076dd254bd967011b68d91b131ce88606
Author: Dave Reisner <dreisner at archlinux.org>
Date:   Sat Oct 20 17:54:08 2012 -0400

    bash-completion: ensure iterators are locally scoped
    
    Avoids leaking the 'i' variable to the user's shell session.

diff --git a/bash-completion/systemd-bash-completion.sh b/bash-completion/systemd-bash-completion.sh
index 1a7df57..a034332 100644
--- a/bash-completion/systemd-bash-completion.sh
+++ b/bash-completion/systemd-bash-completion.sh
@@ -55,7 +55,7 @@ __get_masked_units   () { __systemctl list-unit-files  \
 
 _systemctl () {
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-        local verb comps
+        local i verb comps
 
         local -A OPTS=(
                [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
@@ -203,7 +203,7 @@ __get_all_seats    () { loginctl list-seats    | { while read -r a b; do printf
 
 _loginctl () {
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-        local verb comps
+        local i verb comps
 
         local -A OPTS=(
                [STANDALONE]='--all -a --help -h --no-pager --privileged -P --version'
@@ -341,7 +341,7 @@ _journalctl() {
 complete -F _journalctl journalctl
 
 _timedatectl() {
-        local verb comps
+        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'
@@ -391,7 +391,7 @@ _timedatectl() {
 complete -F _timedatectl timedatectl
 
 _localectl() {
-        local verb comps
+        local i verb comps
         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'
@@ -441,7 +441,7 @@ _localectl() {
 complete -F _localectl localectl
 
 _hostnamectl() {
-        local verb comps
+        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'

commit 26be51de330e544ade97a9345bbfa60d5674cb7a
Author: Dave Reisner <dreisner at archlinux.org>
Date:   Sat Oct 20 17:48:11 2012 -0400

    bash-completion: add completions for hostnamectl

diff --git a/bash-completion/systemd-bash-completion.sh b/bash-completion/systemd-bash-completion.sh
index 636c800..1a7df57 100644
--- a/bash-completion/systemd-bash-completion.sh
+++ b/bash-completion/systemd-bash-completion.sh
@@ -439,3 +439,38 @@ _localectl() {
         return 0
 }
 complete -F _localectl localectl
+
+_hostnamectl() {
+        local 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'
+
+        if [[ $cur = -* ]]; then
+                COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
+                return 0
+        fi
+
+        local -A VERBS=(
+                [STANDALONE]='status'
+                     [ICONS]='set-icon-name'
+                      [NAME]='set-hostname'
+        )
+
+        for ((i=0; i <= COMP_CWORD; i++)); do
+                if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
+                        verb=${COMP_WORDS[i]}
+                        break
+                fi
+        done
+
+        if [[ -z $verb ]]; then
+                comps=${VERBS[*]}
+        elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[ICONS]} ${VERBS[NAME]}; then
+                comps=''
+        fi
+
+        COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+        return 0
+}
+complete -F _hostnamectl hostnamectl



More information about the systemd-commits mailing list