bash-completion: localize words and cword variables

The words and cword variables are not localized in all Bash completion
scripts that call _init_completion.

cur, prev, words, and cword (and split if using the -s flag) are all
variables that should be localized in Bash completion scripts before
calling _init_completion (even if they don't otherwise appear in the
calling script). This is done for cur and prev, but not for words and
cword. Letting words and cword remain unlocalized may clobber variables
the user is using for other purposes, which is bad.

This issue can be resolved by declaring words and cword as local
variables.

Resolves #19188.
This commit is contained in:
Sibo Dong 2021-04-02 23:33:59 -04:00 committed by Zbigniew Jędrzejewski-Szmek
parent 7c20dd4b6e
commit f34173a048
11 changed files with 11 additions and 11 deletions

View file

@ -30,7 +30,7 @@ __get_machines() {
}
_machinectl() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local i verb comps
local -A OPTS=(

View file

@ -30,7 +30,7 @@ __get_links() {
_networkctl() {
local i verb comps
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local -A OPTS=(
[STANDALONE]='-a --all -h --help --version --no-pager --no-legend -s --stats -l --full'
[ARG]='-n --lines'

View file

@ -46,7 +46,7 @@ __get_syscall_sets() {
_systemd_analyze() {
local i verb comps mode
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local -A OPTS=(
[STANDALONE]='-h --help --version --system --user --global --order --require --no-pager

View file

@ -25,7 +25,7 @@ __contains_word() {
}
_systemd_cat() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local i verb comps
local -A OPTS=(

View file

@ -37,7 +37,7 @@ __get_units_have_cgroup() {
}
_systemd_cgls() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local i verb comps
local -A OPTS=(

View file

@ -29,7 +29,7 @@ __get_machines() {
}
_systemd_cgtop() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local comps
local -A OPTS=(

View file

@ -24,7 +24,7 @@ __contains_word() {
}
_systemd-delta() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local comps
local -A OPTS=(

View file

@ -24,7 +24,7 @@ __contains_word() {
}
_systemd_detect_virt() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local i verb comps
local -A OPTS=(

View file

@ -26,7 +26,7 @@ __contains_word () {
_systemd_id128() {
local i verb comps
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local -A OPTS=(
[STANDALONE]='-h --help --version -p --pretty'
[ARG]='-a --app-specific'

View file

@ -58,7 +58,7 @@ __get_rlimit() {
}
_systemd_nspawn() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local i verb comps
local -A OPTS=(

View file

@ -30,7 +30,7 @@ __get_names() {
_systemd_path() {
local comps
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local -A OPTS=(
[STANDALONE]='-h --help --version'
[ARG]='--suffix'