X Tutup
Skip to content

Commit a72d698

Browse files
committed
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...
1 parent 751e757 commit a72d698

File tree

9 files changed

+36
-27
lines changed

9 files changed

+36
-27
lines changed

shell-completion/bash/hostnamectl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919

2020
__contains_word () {
21-
local word=$1; shift
22-
for w in $*; do [[ $w = $word ]] && return 0; done
23-
return 1
21+
local w word=$1; shift
22+
for w in "$@"; do
23+
[[ $w = "$word" ]] && return
24+
done
2425
}
2526

2627
_hostnamectl() {

shell-completion/bash/journalctl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919

2020
__contains_word () {
21-
local word=$1; shift
22-
for w in $*; do [[ $w = $word ]] && return 0; done
23-
return 1
21+
local w word=$1; shift
22+
for w in "$@"; do
23+
[[ $w = "$word" ]] && return
24+
done
2425
}
2526

2627
__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}

shell-completion/bash/localectl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919

2020
__contains_word () {
21-
local word=$1; shift
22-
for w in $*; do [[ $w = $word ]] && return 0; done
23-
return 1
21+
local w word=$1; shift
22+
for w in "$@"; do
23+
[[ $w = "$word" ]] && return
24+
done
2425
}
2526

2627
_localectl() {

shell-completion/bash/loginctl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919

2020
__contains_word () {
21-
local word=$1; shift
22-
for w in $*; do [[ $w = $word ]] && return 0; done
23-
return 1
21+
local w word=$1; shift
22+
for w in "$@"; do
23+
[[ $w = "$word" ]] && return
24+
done
2425
}
2526

2627
__get_all_sessions () { loginctl list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; }

shell-completion/bash/systemctl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ __systemd_properties() {
3232
}
3333

3434
__contains_word () {
35-
local word=$1; shift
36-
for w in $*; do [[ $w = $word ]] && return 0; done
37-
return 1
35+
local w word=$1; shift
36+
for w in "$@"; do
37+
[[ $w = "$word" ]] && return
38+
done
3839
}
3940

4041
__filter_units_by_property () {

shell-completion/bash/systemd-analyze

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
2020

2121
__contains_word () {
22-
local word=$1; shift
23-
for w in $*; do [[ $w = $word ]] && return 0; done
24-
return 1
22+
local w word=$1; shift
23+
for w in "$@"; do
24+
[[ $w = "$word" ]] && return
25+
done
2526
}
2627

2728
_systemd_analyze() {

shell-completion/bash/systemd-coredumpctl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919

2020
__contains_word () {
21-
local word=$1; shift
22-
for w in $*; do [[ $w = $word ]] && return 0; done
23-
return 1
21+
local w word=$1; shift
22+
for w in "$@"; do
23+
[[ $w = "$word" ]] && return
24+
done
2425
}
2526

2627
__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}

shell-completion/bash/timedatectl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919

2020
__contains_word () {
21-
local word=$1; shift
22-
for w in $*; do [[ $w = $word ]] && return 0; done
23-
return 1
21+
local w word=$1; shift
22+
for w in "$@"; do
23+
[[ $w = "$word" ]] && return
24+
done
2425
}
2526

2627
_timedatectl() {

shell-completion/bash/udevadm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
1919

2020
__contains_word () {
21-
local word=$1; shift
22-
for w in $*; do [[ $w = $word ]] && return 0; done
23-
return 1
21+
local w word=$1; shift
22+
for w in "$@"; do
23+
[[ $w = "$word" ]] && return
24+
done
2425
}
2526

2627
__get_all_sysdevs() {

0 commit comments

Comments
 (0)
X Tutup