From a72d698d0d9ff9c158155b44cdc77376df31a317 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 30 Jul 2013 12:46:23 -0400 Subject: [PATCH] bash-completion: use a better definition of __contains_word - scope the iterator var - use the correct, quoted, non-expansion prone positional parameter notation - prevent expansion on RHS of comparison - remove unneeded explicit returns. This really should be defined only once... --- shell-completion/bash/hostnamectl | 7 ++++--- shell-completion/bash/journalctl | 7 ++++--- shell-completion/bash/localectl | 7 ++++--- shell-completion/bash/loginctl | 7 ++++--- shell-completion/bash/systemctl | 7 ++++--- shell-completion/bash/systemd-analyze | 7 ++++--- shell-completion/bash/systemd-coredumpctl | 7 ++++--- shell-completion/bash/timedatectl | 7 ++++--- shell-completion/bash/udevadm | 7 ++++--- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/shell-completion/bash/hostnamectl b/shell-completion/bash/hostnamectl index a57bffe15..38ab1344f 100644 --- a/shell-completion/bash/hostnamectl +++ b/shell-completion/bash/hostnamectl @@ -18,9 +18,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } _hostnamectl() { diff --git a/shell-completion/bash/journalctl b/shell-completion/bash/journalctl index 29bf6bca3..3c40d57a9 100644 --- a/shell-completion/bash/journalctl +++ b/shell-completion/bash/journalctl @@ -18,9 +18,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} diff --git a/shell-completion/bash/localectl b/shell-completion/bash/localectl index ef19f0146..bec9e78c6 100644 --- a/shell-completion/bash/localectl +++ b/shell-completion/bash/localectl @@ -18,9 +18,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } _localectl() { diff --git a/shell-completion/bash/loginctl b/shell-completion/bash/loginctl index 1844085d4..3104b305f 100644 --- a/shell-completion/bash/loginctl +++ b/shell-completion/bash/loginctl @@ -18,9 +18,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } __get_all_sessions () { loginctl list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; } diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl index ceca3348e..517b49a6a 100644 --- a/shell-completion/bash/systemctl +++ b/shell-completion/bash/systemctl @@ -32,9 +32,10 @@ __systemd_properties() { } __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } __filter_units_by_property () { diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze index 11276ef09..33833aac1 100644 --- a/shell-completion/bash/systemd-analyze +++ b/shell-completion/bash/systemd-analyze @@ -19,9 +19,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } _systemd_analyze() { diff --git a/shell-completion/bash/systemd-coredumpctl b/shell-completion/bash/systemd-coredumpctl index 4bbece734..805e84824 100644 --- a/shell-completion/bash/systemd-coredumpctl +++ b/shell-completion/bash/systemd-coredumpctl @@ -18,9 +18,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} diff --git a/shell-completion/bash/timedatectl b/shell-completion/bash/timedatectl index 2842b3106..c6a654525 100644 --- a/shell-completion/bash/timedatectl +++ b/shell-completion/bash/timedatectl @@ -18,9 +18,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } _timedatectl() { diff --git a/shell-completion/bash/udevadm b/shell-completion/bash/udevadm index e9ad17920..e521a3bbb 100644 --- a/shell-completion/bash/udevadm +++ b/shell-completion/bash/udevadm @@ -18,9 +18,10 @@ # along with systemd; If not, see . __contains_word () { - local word=$1; shift - for w in $*; do [[ $w = $word ]] && return 0; done - return 1 + local w word=$1; shift + for w in "$@"; do + [[ $w = "$word" ]] && return + done } __get_all_sysdevs() { -- 2.30.2