Skip to content

Commit e76ca14

Browse files
committed
refactor: simplify function names of the _comp_get_comp_words family
* rename `_comp_get{_comp => }_words{_by_ref => }` * rename `_comp__reassemble{_comp => }_words{_by_ref => }` * rename `_comp__get_cword_at_cursor{_by_ref => }`
1 parent a2d8ac2 commit e76ca14

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

bash_completion

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ _comp_looks_like_path()
394394
# @param $2 words Name of variable to return words to
395395
# @param $3 cword Name of variable to return cword to
396396
#
397-
_comp__reassemble_comp_words_by_ref()
397+
_comp__reassemble_words()
398398
{
399399
local exclude i j line ref
400400
# Exclude word separator characters?
@@ -454,7 +454,7 @@ _comp__reassemble_comp_words_by_ref()
454454
printf -v "$2[i]" %s "${COMP_WORDS[i]}"
455455
done
456456
fi
457-
} # _comp__reassemble_comp_words_by_ref()
457+
} # _comp__reassemble_words()
458458

459459
# @param $1 exclude Characters out of $COMP_WORDBREAKS which should NOT be
460460
# considered word breaks. This is useful for things like scp where
@@ -463,11 +463,11 @@ _comp__reassemble_comp_words_by_ref()
463463
# @param $2 words Name of variable to return words to
464464
# @param $3 cword Name of variable to return cword to
465465
# @param $4 cur Name of variable to return current word to complete to
466-
# @see _comp__reassemble_comp_words_by_ref()
467-
_comp__get_cword_at_cursor_by_ref()
466+
# @see _comp__reassemble_words()
467+
_comp__get_cword_at_cursor()
468468
{
469469
local cword words=()
470-
_comp__reassemble_comp_words_by_ref "$1" words cword
470+
_comp__reassemble_words "$1" words cword
471471

472472
local i cur="" index=$COMP_POINT lead=${COMP_LINE:0:COMP_POINT}
473473
# Cursor not at position 0 and not led by just space(s)?
@@ -508,7 +508,7 @@ _comp__get_cword_at_cursor_by_ref()
508508
# (For example, if the line is "ls foobar",
509509
# and the cursor is here --------> ^
510510
# Also one is able to cross over possible wordbreak characters.
511-
# Usage: _comp_get_comp_words_by_ref [OPTIONS] [VARNAMES]
511+
# Usage: _comp_get_words [OPTIONS] [VARNAMES]
512512
# Available VARNAMES:
513513
# cur Return cur via $cur
514514
# prev Return prev via $prev
@@ -527,9 +527,9 @@ _comp__get_cword_at_cursor_by_ref()
527527
#
528528
# Example usage:
529529
#
530-
# $ _comp_get_comp_words_by_ref -n : cur prev
530+
# $ _comp_get_words -n : cur prev
531531
#
532-
_comp_get_comp_words_by_ref()
532+
_comp_get_words()
533533
{
534534
local exclude flag i OPTIND=1
535535
local cur cword words=()
@@ -564,7 +564,7 @@ _comp_get_comp_words_by_ref()
564564
((OPTIND += 1))
565565
done
566566

567-
_comp__get_cword_at_cursor_by_ref "${exclude-}" words cword cur
567+
_comp__get_cword_at_cursor "${exclude-}" words cword cur
568568

569569
[[ -v vcur ]] && {
570570
upvars+=("$vcur")
@@ -895,7 +895,7 @@ _comp_variable_assignments()
895895
# cur, prev, words, and cword are local, ditto split if you use -s.
896896
#
897897
# Options:
898-
# -n EXCLUDE Passed to _comp_get_comp_words_by_ref -n with redirection chars
898+
# -n EXCLUDE Passed to _comp_get_words -n with redirection chars
899899
# -e XSPEC Passed to _filedir as first arg for stderr redirections
900900
# -o XSPEC Passed to _filedir as first arg for other output redirections
901901
# -i XSPEC Passed to _filedir as first arg for stdin redirections
@@ -943,7 +943,7 @@ _comp_initialize()
943943

944944
COMPREPLY=()
945945
local redir='@(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|<?([>&])|<<?([-<]))|&>?(>))'
946-
_comp_get_comp_words_by_ref -n "$exclude<>&" cur prev words cword
946+
_comp_get_words -n "$exclude<>&" cur prev words cword
947947

948948
# Complete variable names.
949949
_variables && return 1
@@ -1682,7 +1682,7 @@ _realcommand()
16821682

16831683
# This function returns the first argument, excluding options
16841684
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
1685-
# NOT be considered word breaks. See _comp__reassemble_comp_words_by_ref.
1685+
# NOT be considered word breaks. See _comp__reassemble_words.
16861686
_get_first_arg()
16871687
{
16881688
local i
@@ -1698,13 +1698,13 @@ _get_first_arg()
16981698

16991699
# This function counts the number of args, excluding options
17001700
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
1701-
# NOT be considered word breaks. See _comp__reassemble_comp_words_by_ref.
1701+
# NOT be considered word breaks. See _comp__reassemble_words.
17021702
# @param $2 glob Options whose following argument should not be counted
17031703
# @param $3 glob Options that should be counted as args
17041704
_count_args()
17051705
{
17061706
local i cword words
1707-
_comp__reassemble_comp_words_by_ref "${1-}" words cword
1707+
_comp__reassemble_words "${1-}" words cword
17081708

17091709
args=1
17101710
for ((i = 1; i < cword; i++)); do
@@ -2163,7 +2163,7 @@ _comp_command_offset()
21632163

21642164
COMPREPLY=()
21652165
local cur
2166-
_comp_get_comp_words_by_ref cur
2166+
_comp_get_words cur
21672167

21682168
if ((COMP_CWORD == 0)); then
21692169
local IFS=$'\n'

bash_completion.d/000_bash_completion_compat

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ _comp_deprecate_func _command _comp_command
1010
_comp_deprecate_func _root_command _comp_root_command
1111
_comp_deprecate_func _xfunc _comp_xfunc
1212
_comp_deprecate_func _upvars _comp_upvars
13-
_comp_deprecate_func __reassemble_comp_words_by_ref _comp__reassemble_comp_words_by_ref
14-
_comp_deprecate_func __get_cword_at_cursor_by_ref _comp__get_cword_at_cursor_by_ref
15-
_comp_deprecate_func _get_comp_words_by_ref _comp_get_comp_words_by_ref
13+
_comp_deprecate_func __reassemble_comp_words_by_ref _comp__reassemble_words
14+
_comp_deprecate_func __get_cword_at_cursor_by_ref _comp__get_cword_at_cursor
15+
_comp_deprecate_func _get_comp_words_by_ref _comp_get_words
1616

1717
# Backwards compatibility for compat completions that use have().
1818
# @deprecated should no longer be used; generally not needed with dynamically
@@ -83,13 +83,13 @@ _upvar()
8383
# current word (default is 0, previous is 1), respecting the exclusions
8484
# given at $1. For example, `_get_cword "=:" 1' returns the word left of
8585
# the current word, respecting the exclusions "=:".
86-
# @deprecated Use `_comp_get_comp_words_by_ref cur' instead
87-
# @see _comp_get_comp_words_by_ref()
86+
# @deprecated Use `_comp_get_words cur' instead
87+
# @see _comp_get_words()
8888
_get_cword()
8989
{
9090
local LC_CTYPE=C
9191
local cword words
92-
_comp__reassemble_comp_words_by_ref "${1-}" words cword
92+
_comp__reassemble_words "${1-}" words cword
9393

9494
# return previous word offset by $2
9595
if [[ ${2-} && ${2//[^0-9]/} ]]; then
@@ -134,8 +134,8 @@ _get_cword()
134134
# This is a good alternative to `prev=${COMP_WORDS[COMP_CWORD-1]}' because bash4
135135
# will properly return the previous word with respect to any given exclusions to
136136
# COMP_WORDBREAKS.
137-
# @deprecated Use `_comp_get_comp_words_by_ref cur prev' instead
138-
# @see _comp_get_comp_words_by_ref()
137+
# @deprecated Use `_comp_get_words cur prev' instead
138+
# @see _comp_get_words()
139139
#
140140
_get_pword()
141141
{

completions/ssh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ _comp_xfunc_ssh_suboption_check()
218218
{
219219
# Get prev and cur words without splitting on =
220220
local cur prev
221-
_comp_get_comp_words_by_ref -n := cur prev
221+
_comp_get_words -n := cur prev
222222
if [[ $cur == *=* && $prev == -*o ]]; then
223223
_ssh_suboption "$cur" "${1-}"
224224
return $?

test/t/test_umount.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def dummy_mnt(self, request, bash):
1919
assert_bash_exec(
2020
bash,
2121
"_mnt_completion() { "
22-
"local cur prev;_comp_get_comp_words_by_ref cur prev; "
22+
"local cur prev;_comp_get_words cur prev; "
2323
'_comp_cmd_umount__linux_fstab "$prev" < mount/test-fstab; '
2424
"} && complete -F _mnt_completion _mnt",
2525
)

test/t/unit/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ EXTRA_DIST = \
88
test_unit_expand_tilde_by_ref.py \
99
test_unit_filedir.py \
1010
test_unit_find_unique_completion_pair.py \
11-
test_unit_get_comp_words_by_ref.py \
11+
test_unit_get_words.py \
1212
test_unit_get_cword.py \
1313
test_unit_initialize.py \
1414
test_unit_ip_addresses.py \

test/t/unit/test_unit_filedir.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ class TestUnitFiledir:
1515
def functions(self, request, bash):
1616
assert_bash_exec(
1717
bash,
18-
"_f() { local cur;_comp_get_comp_words_by_ref cur; unset -v COMPREPLY; _filedir; }; "
18+
"_f() { local cur;_comp_get_words cur; unset -v COMPREPLY; _filedir; }; "
1919
"complete -F _f f; "
2020
"complete -F _f -o filenames f2",
2121
)
2222
assert_bash_exec(
2323
bash,
24-
"_g() { local cur;_comp_get_comp_words_by_ref cur; unset -v COMPREPLY; _filedir e1; }; "
24+
"_g() { local cur;_comp_get_words cur; unset -v COMPREPLY; _filedir e1; }; "
2525
"complete -F _g g",
2626
)
2727
assert_bash_exec(
2828
bash,
29-
"_fd() { local cur;_comp_get_comp_words_by_ref cur; unset -v COMPREPLY; _filedir -d; };"
29+
"_fd() { local cur;_comp_get_words cur; unset -v COMPREPLY; _filedir -d; };"
3030
"complete -F _fd fd",
3131
)
3232

test/t/unit/test_unit_get_comp_words_by_ref.py renamed to test/t/unit/test_unit_get_words.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestUnitGetCompWordsByRef(TestUnitBase):
1111
def _test(self, bash, *args, **kwargs):
1212
assert_bash_exec(bash, "unset cur prev")
1313
output = self._test_unit(
14-
"_comp_get_comp_words_by_ref %s cur prev; echo $cur,${prev-}",
14+
"_comp_get_words %s cur prev; echo $cur,${prev-}",
1515
bash,
1616
*args,
1717
**kwargs,
@@ -22,7 +22,7 @@ def test_1(self, bash):
2222
assert_bash_exec(
2323
bash,
2424
"COMP_WORDS=() COMP_CWORD= COMP_POINT= COMP_LINE= "
25-
"_comp_get_comp_words_by_ref cur >/dev/null",
25+
"_comp_get_words cur >/dev/null",
2626
)
2727

2828
def test_2(self, bash):
@@ -134,9 +134,9 @@ def test_22(self, bash):
134134
def test_23(self, bash):
135135
"""a -n|
136136
137-
This test makes sure `_comp_get_comp_words_by_ref' doesn't use
138-
`echo' to return its value, because -n might be interpreted by
139-
`echo' and thus would not be returned.
137+
This test makes sure `_comp_get_words' doesn't use `echo' to
138+
return its value, because -n might be interpreted by `echo'
139+
and thus would not be returned.
140140
"""
141141
output = self._test(bash, "(a -n)", 1, "a -n", 4)
142142
assert output == "-n,a"
@@ -175,7 +175,7 @@ def test_30(self, bash):
175175
"""a b| to all vars"""
176176
assert_bash_exec(bash, "unset words cword cur prev")
177177
output = self._test_unit(
178-
"_comp_get_comp_words_by_ref words cword cur prev%s; "
178+
"_comp_get_words words cword cur prev%s; "
179179
'echo "${words[@]}",$cword,$cur,$prev',
180180
bash,
181181
"(a b)",
@@ -189,7 +189,7 @@ def test_31(self, bash):
189189
"""a b| to alternate vars"""
190190
assert_bash_exec(bash, "unset words2 cword2 cur2 prev2")
191191
output = self._test_unit(
192-
"_comp_get_comp_words_by_ref -w words2 -i cword2 -c cur2 -p prev2%s; "
192+
"_comp_get_words -w words2 -i cword2 -c cur2 -p prev2%s; "
193193
'echo $cur2,$prev2,"${words2[@]}",$cword2',
194194
bash,
195195
"(a b)",
@@ -204,7 +204,7 @@ def test_32(self, bash):
204204
"""a b : c| with wordbreaks -= :"""
205205
assert_bash_exec(bash, "unset words")
206206
output = self._test_unit(
207-
'_comp_get_comp_words_by_ref -n : words%s; echo "${words[@]}"',
207+
'_comp_get_words -n : words%s; echo "${words[@]}"',
208208
bash,
209209
"(a b : c)",
210210
3,
@@ -217,7 +217,7 @@ def test_33(self, bash):
217217
"""a b: c| with wordbreaks -= :"""
218218
assert_bash_exec(bash, "unset words")
219219
output = self._test_unit(
220-
'_comp_get_comp_words_by_ref -n : words%s; echo "${words[@]}"',
220+
'_comp_get_words -n : words%s; echo "${words[@]}"',
221221
bash,
222222
"(a b : c)",
223223
3,
@@ -230,7 +230,7 @@ def test_34(self, bash):
230230
"""a b :c| with wordbreaks -= :"""
231231
assert_bash_exec(bash, "unset words")
232232
output = self._test_unit(
233-
'_comp_get_comp_words_by_ref -n : words%s; echo "${words[@]}"',
233+
'_comp_get_words -n : words%s; echo "${words[@]}"',
234234
bash,
235235
"(a b : c)",
236236
3,
@@ -243,7 +243,7 @@ def test_35(self, bash):
243243
r"""a b\ :c| with wordbreaks -= :"""
244244
assert_bash_exec(bash, "unset words")
245245
output = self._test_unit(
246-
'_comp_get_comp_words_by_ref -n : words%s; echo "${words[@]}"',
246+
'_comp_get_words -n : words%s; echo "${words[@]}"',
247247
bash,
248248
"(a 'b ' : c)",
249249
3,
@@ -255,6 +255,6 @@ def test_35(self, bash):
255255
def test_unknown_arg_error(self, bash):
256256
with pytest.raises(AssertionError) as ex:
257257
_ = assert_bash_exec(
258-
bash, "_comp_get_comp_words_by_ref dummy", want_output=True
258+
bash, "_comp_get_words dummy", want_output=True
259259
)
260260
ex.match("dummy.* unknown argument")

test/t/unit/test_unit_ip_addresses.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ class TestUnitIpAddresses:
99
def functions(self, request, bash):
1010
assert_bash_exec(
1111
bash,
12-
"_ia() { local cur;_comp_get_comp_words_by_ref cur;"
12+
"_ia() { local cur;_comp_get_words cur;"
1313
"unset -v COMPREPLY;_ip_addresses; }",
1414
)
1515
assert_bash_exec(bash, "complete -F _ia ia")
1616
assert_bash_exec(
1717
bash,
18-
"_iaa() { local cur;_comp_get_comp_words_by_ref cur;"
18+
"_iaa() { local cur;_comp_get_words cur;"
1919
"unset -v COMPREPLY;_ip_addresses -a; }",
2020
)
2121
assert_bash_exec(bash, "complete -F _iaa iaa")
2222
assert_bash_exec(
2323
bash,
24-
" _ia6() { local cur;_comp_get_comp_words_by_ref cur;"
24+
" _ia6() { local cur;_comp_get_words cur;"
2525
"unset -v COMPREPLY;_ip_addresses -6; }",
2626
)
2727
assert_bash_exec(bash, "complete -F _ia6 ia6")

0 commit comments

Comments
 (0)