Skip to content

Commit

Permalink
fix(_comp_count_args): exclude <>& from wordbreaks as _comp_initialize
Browse files Browse the repository at this point in the history
In the current implementation, to count the number of arguments, we
reassemble `cword` and `words` by specified exclude chars (i.e.,
characters that should not be considered word breaks even though they
are in COMP_WORDBREAKS).  The reassembly by the top-level
`_comp_initialize` always specify `<>&` as exclude chars, but the
current implementaion of `_comp_count_args` do not specify them.  This
patch specifies `<>&` for `_comp_count_args` in accordance with
`_comp_initialize`.
  • Loading branch information
akinomyoga committed Sep 2, 2023
1 parent 0384bd5 commit 521d2bb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bash_completion
Expand Up @@ -2221,7 +2221,7 @@ _comp_get_first_arg()
_comp_count_args()
{
local i cword words
_comp__reassemble_words "${1-}" words cword
_comp__reassemble_words "${1-}<>&" words cword

ret=1
for ((i = 1; i < cword; i++)); do
Expand Down
2 changes: 1 addition & 1 deletion test/t/unit/test_unit_count_args.py
Expand Up @@ -13,7 +13,7 @@ def _test(self, *args, **kwargs):
)

def test_1(self, bash):
assert_bash_exec(bash, "COMP_CWORD= _comp_count_args")
assert_bash_exec(bash, "COMP_LINE= COMP_POINT=0 COMP_WORDS=() COMP_CWORD=; _comp_count_args")

def test_2(self, bash):
"""a b| should set args to 1"""
Expand Down

0 comments on commit 521d2bb

Please sign in to comment.