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...
This commit is contained in:
Dave Reisner 2013-07-30 12:46:23 -04:00
parent 751e75769a
commit a72d698d0d
9 changed files with 36 additions and 27 deletions

View file

@ -18,9 +18,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
_hostnamectl() { _hostnamectl() {

View file

@ -18,9 +18,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}

View file

@ -18,9 +18,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
_localectl() { _localectl() {

View file

@ -18,9 +18,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
__get_all_sessions () { loginctl list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; } __get_all_sessions () { loginctl list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; }

View file

@ -32,9 +32,10 @@ __systemd_properties() {
} }
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
__filter_units_by_property () { __filter_units_by_property () {

View file

@ -19,9 +19,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
_systemd_analyze() { _systemd_analyze() {

View file

@ -18,9 +18,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}

View file

@ -18,9 +18,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
_timedatectl() { _timedatectl() {

View file

@ -18,9 +18,10 @@
# along with systemd; If not, see <http://www.gnu.org/licenses/>. # along with systemd; If not, see <http://www.gnu.org/licenses/>.
__contains_word () { __contains_word () {
local word=$1; shift local w word=$1; shift
for w in $*; do [[ $w = $word ]] && return 0; done for w in "$@"; do
return 1 [[ $w = "$word" ]] && return
done
} }
__get_all_sysdevs() { __get_all_sysdevs() {