chiark / gitweb /
bash-completion: use a better definition of __contains_word
authorDave Reisner <dreisner@archlinux.org>
Tue, 30 Jul 2013 16:46:23 +0000 (12:46 -0400)
committerDave Reisner <dreisner@archlinux.org>
Tue, 30 Jul 2013 17:04:46 +0000 (13:04 -0400)
- 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
shell-completion/bash/journalctl
shell-completion/bash/localectl
shell-completion/bash/loginctl
shell-completion/bash/systemctl
shell-completion/bash/systemd-analyze
shell-completion/bash/systemd-coredumpctl
shell-completion/bash/timedatectl
shell-completion/bash/udevadm

index a57bffe15f7647525d2ac6ba04b2bd9c39d5898e..38ab1344f3f31ee67faaed3cf7293623bc3168e5 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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() {
index 29bf6bca3fe95f6739788e7ea7aa2cbdd807693c..3c40d57a98f9d7d0cd9298e3e07426abbac6a3c0 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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}
index ef19f01461ced6321fc0aa558cf9c9ca13624060..bec9e78c64b1a531a6303f2a0ec566dfe0205107 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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() {
index 1844085d49ee76a49a1e28570a2e424040f349e7..3104b305fa49b55c5e344b67272730ed4c96e4b1 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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; } ; }
index ceca3348eddc2d1c6dd23aafd5a2417459356cfa..517b49a6afda79ed587518cbf80431660d1f71bd 100644 (file)
@@ -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 () {
index 11276ef09cd68b1c75bec21c88702b4191257443..33833aac105f0c0351660dd6c13e14fe3da8d9a2 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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() {
index 4bbece7347a09d9e5294aee5af29260c01f2d9e2..805e84824e384882e1307bb81aa0543193558093 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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}
index 2842b3106925d81fb470f670b1cd439a748792f6..c6a6545257215201cf0f75cd0a0fe5eb888c6809 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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() {
index e9ad1792034ce787098fa13001a90bce7fc4d088..e521a3bbb696c47fa4fdefa3ee32edf2c036b893 100644 (file)
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
 __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() {