Skip to content

Commit

Permalink
fix(_comp_compgen): do not inherit -a for explicitly specified var
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 17, 2023
1 parent 0661fb5 commit 3c20766
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ _comp_compgen__error_fallback()
# @since 2.12
_comp_compgen()
{
local _append=${_comp_compgen__append-}
local _var=${_comp_compgen__var-COMPREPLY}
local _append=
local _var=
local _cur=${_comp_compgen__cur-${cur-}}
local _dir=""
local _ifs=$' \t\n' _has_ifs=""
Expand Down Expand Up @@ -592,6 +592,11 @@ _comp_compgen()
printf 'usage: %s [-alR|-F SEP|-v ARR|-c CUR] -- ARGS...' "$FUNCNAME" >&2
return 2
fi
if [[ ! $_var ]]; then
# Inherit _append and _var only when -v var is unspecified.
_var=${_comp_compgen__var-COMPREPLY}
[[ $_append ]] || _append=${_comp_compgen__append-}
fi

if [[ $1 != -* ]]; then
# usage: _comp_compgen [options] NAME args
Expand Down
13 changes: 13 additions & 0 deletions test/t/unit/test_unit_compgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def functions(self, bash):
"_comp_compgen_gen8() { local -a arr=(x y z); _comp_compgen -U arr -- -W '\"${arr[@]}\"'; }",
)

# test_9_inherit_a
assert_bash_exec(
bash,
'_comp_compgen_gen9sub() { local -a gen=(00); _comp_compgen -v gen -- -W 11; _comp_compgen_set "${gen[@]}"; }; '
"_comp_compgen_gen9() { _comp_compgen_gen9sub; _comp_compgen -a gen9sub; }",
)

def test_1_basic(self, bash, functions):
output = assert_bash_exec(
bash, "_comp__test_words 12 34 56 ''", want_output=True
Expand Down Expand Up @@ -158,3 +165,9 @@ def test_8_option_U(self, bash, functions):
bash, "_comp__test_compgen gen8", want_output=True
)
assert output.strip() == "<x><y><z>"

def test_9_inherit_a(self, bash, functions):
output = assert_bash_exec(
bash, "_comp__test_compgen gen9", want_output=True
)
assert output.strip() == "<11><11>"

0 comments on commit 3c20766

Please sign in to comment.