From: Sibo Dong Date: Sat, 3 Apr 2021 03:33:59 +0000 (-0400) Subject: bash-completion: localize words and cword variables X-Git-Tag: v249-rc1~473 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f34173a048061b3f7e551e9a7c04f00e5a106fac;p=thirdparty%2Fsystemd.git 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. --- diff --git a/shell-completion/bash/machinectl b/shell-completion/bash/machinectl index cd16e477213..bc3a7889b38 100644 --- a/shell-completion/bash/machinectl +++ b/shell-completion/bash/machinectl @@ -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=( diff --git a/shell-completion/bash/networkctl b/shell-completion/bash/networkctl index 9282ee87377..ab2a5f7015e 100644 --- a/shell-completion/bash/networkctl +++ b/shell-completion/bash/networkctl @@ -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' diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze index 92f81a60fc7..eded49b50e7 100644 --- a/shell-completion/bash/systemd-analyze +++ b/shell-completion/bash/systemd-analyze @@ -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 diff --git a/shell-completion/bash/systemd-cat b/shell-completion/bash/systemd-cat index 9413b6fa70a..737f33981bb 100644 --- a/shell-completion/bash/systemd-cat +++ b/shell-completion/bash/systemd-cat @@ -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=( diff --git a/shell-completion/bash/systemd-cgls b/shell-completion/bash/systemd-cgls index 7caaf89ddb9..0b6a8fda0d2 100644 --- a/shell-completion/bash/systemd-cgls +++ b/shell-completion/bash/systemd-cgls @@ -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=( diff --git a/shell-completion/bash/systemd-cgtop b/shell-completion/bash/systemd-cgtop index b186f1bd537..2c59b6c9f69 100644 --- a/shell-completion/bash/systemd-cgtop +++ b/shell-completion/bash/systemd-cgtop @@ -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=( diff --git a/shell-completion/bash/systemd-delta b/shell-completion/bash/systemd-delta index baf86b08134..f97b6dd5b2e 100644 --- a/shell-completion/bash/systemd-delta +++ b/shell-completion/bash/systemd-delta @@ -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=( diff --git a/shell-completion/bash/systemd-detect-virt b/shell-completion/bash/systemd-detect-virt index fb35efaadb9..0c9da3a22e1 100644 --- a/shell-completion/bash/systemd-detect-virt +++ b/shell-completion/bash/systemd-detect-virt @@ -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=( diff --git a/shell-completion/bash/systemd-id128 b/shell-completion/bash/systemd-id128 index 937556154a8..25110d13091 100644 --- a/shell-completion/bash/systemd-id128 +++ b/shell-completion/bash/systemd-id128 @@ -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' diff --git a/shell-completion/bash/systemd-nspawn b/shell-completion/bash/systemd-nspawn index ebd97a9de1b..ed1296a8788 100644 --- a/shell-completion/bash/systemd-nspawn +++ b/shell-completion/bash/systemd-nspawn @@ -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=( diff --git a/shell-completion/bash/systemd-path b/shell-completion/bash/systemd-path index cae4ac1b309..4330c3e05b3 100644 --- a/shell-completion/bash/systemd-path +++ b/shell-completion/bash/systemd-path @@ -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'