]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bash-completion: localize words and cword variables
authorSibo Dong <dongsibo@users.noreply.github.com>
Sat, 3 Apr 2021 03:33:59 +0000 (23:33 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 6 Apr 2021 14:15:13 +0000 (16:15 +0200)
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.

shell-completion/bash/machinectl
shell-completion/bash/networkctl
shell-completion/bash/systemd-analyze
shell-completion/bash/systemd-cat
shell-completion/bash/systemd-cgls
shell-completion/bash/systemd-cgtop
shell-completion/bash/systemd-delta
shell-completion/bash/systemd-detect-virt
shell-completion/bash/systemd-id128
shell-completion/bash/systemd-nspawn
shell-completion/bash/systemd-path

index cd16e47721350060ac4a21617d6c5cd520c0e5d8..bc3a7889b3882e1b0fb880ae1721c49b286a40d9 100644 (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=(
index 9282ee873773cabcf429d031529b8408087d0a86..ab2a5f7015ef6f1786f94e565e7a851e0f585992 100644 (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'
index 92f81a60fc718261a1489546bf9381c9c7980ea2..eded49b50e7d769029c7c1e1eca62e3ab7c7c2d9 100644 (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
index 9413b6fa70ab00ca72a687eef46b214b13c93e82..737f33981bb5a30ff255be6c73c2caa39c473206 100644 (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=(
index 7caaf89ddb903a34f32f2a6b2dddfc990283767d..0b6a8fda0d28319715f1d9c2c06a9270e80b67f8 100644 (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=(
index b186f1bd537ca37018ac113a5789309a98c3c2f7..2c59b6c9f69d36bce9a0d9554193338b18be1e05 100644 (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=(
index baf86b081343d64822ce70dcbada1dc1863f0071..f97b6dd5b2eabbc0d22769c76c4faed5d288f34d 100644 (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=(
index fb35efaadb9648faff181d340649cbbc00c66214..0c9da3a22e1ad0adfd4f8e3dc7ab35498373511b 100644 (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=(
index 937556154a8593e42f815adacb05528aca861653..25110d13091948c1d92e50a6bbf22c515f8e3aad 100644 (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'
index ebd97a9de1b683205050814a8e54c53453ad2276..ed1296a87883cba8e3c47a0cf4c4415372011a45 100644 (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=(
index cae4ac1b3093f4e04c667f7705e296feb5bcf619..4330c3e05b32d81fc555019fb846abe7ff1a57f2 100644 (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'