Skip to content

Commit 6e8a154

Browse files
committed
refactor: rename { => _comp_compgen}_filedir
1 parent e34e38f commit 6e8a154

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

bash_completion

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,7 @@ _comp_quote_compgen()
828828
# completions with `.$1' and the uppercase version of it as file
829829
# extension.
830830
#
831-
# TODO: rename per API conventions
832-
_filedir()
831+
_comp_compgen_filedir()
833832
{
834833
_tilde "${cur-}" || return
835834

@@ -867,11 +866,11 @@ _filedir()
867866
fi
868867

869868
if ((${#toks[@]} != 0)); then
870-
# 2>/dev/null for direct invocation, e.g. in the _filedir unit test
869+
# 2>/dev/null for direct invocation, e.g. in the _comp_compgen_filedir unit test
871870
compopt -o filenames 2>/dev/null
872-
COMPREPLY+=("${toks[@]}")
871+
_comp_compgen -R -- -W '"${toks[@]}"'
873872
fi
874-
} # _filedir()
873+
} # _comp_compgen_filedir()
875874

876875
# This function splits $cur=--foo=bar into $prev=--foo, $cur=bar, making it
877876
# easier to support both "--foo bar" and "--foo=bar" style completions.

bash_completion.d/000_bash_completion_compat.bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,10 @@ _command_offset()
258258
_comp_command_offset "$@"
259259
}
260260

261+
# @deprecated Use `_comp_compgen -a filedir`
262+
_filedir()
263+
{
264+
_comp_compgen -a filedir "$@"
265+
}
266+
261267
# ex: filetype=sh

test/t/unit/test_unit_filedir.py

Lines changed: 4 additions & 4 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_words cur; unset -v COMPREPLY; _filedir; }; "
18+
"_f() { local cur;_comp_get_words cur; unset -v COMPREPLY; _comp_compgen_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_words cur; unset -v COMPREPLY; _filedir e1; }; "
24+
"_g() { local cur;_comp_get_words cur; unset -v COMPREPLY; _comp_compgen_filedir e1; }; "
2525
"complete -F _g g",
2626
)
2727
assert_bash_exec(
2828
bash,
29-
"_fd() { local cur;_comp_get_words cur; unset -v COMPREPLY; _filedir -d; };"
29+
"_fd() { local cur;_comp_get_words cur; unset -v COMPREPLY; _comp_compgen_filedir -d; };"
3030
"complete -F _fd fd",
3131
)
3232

@@ -59,7 +59,7 @@ def utf8_ctype(self, bash):
5959
return lc_ctype
6060

6161
def test_1(self, bash):
62-
assert_bash_exec(bash, "_filedir >/dev/null")
62+
assert_bash_exec(bash, "_comp_compgen_filedir >/dev/null")
6363

6464
@pytest.mark.parametrize("funcname", "f f2".split())
6565
def test_2(self, bash, functions, funcname):

test/t/unit/test_unit_quote_compgen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def test_github_issue_492_2(self, bash, functions):
116116
def test_github_issue_492_3(self, bash, functions):
117117
"""Test code execution through unintended pathname expansions
118118
119-
When there is a file named "quote=$(COMMAND)" (for _filedir) or
120-
"ret=$(COMMAND)" (for _comp_quote_compgen), the completion of the word
121-
'$* results in the execution of COMMAND.
119+
When there is a file named "quote=$(COMMAND)" (for
120+
_comp_compgen_filedir) or "ret=$(COMMAND)" (for _comp_quote_compgen),
121+
the completion of the word '$* results in the execution of COMMAND.
122122
123123
$ echo '$*[TAB]
124124

0 commit comments

Comments
 (0)