-
Notifications
You must be signed in to change notification settings - Fork 391
refactor: { => _comp_compgen}_filedir
and _comp_compgen [opts] NAME
#952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
{ => _comp_compgen}_filedir
and _comp_compgen [opts] NAME
(idea){ => _comp_compgen}_filedir
and _comp_compgen [opts] NAME
65fb85b
to
310c3b9
Compare
{ => _comp_compgen}_filedir
and _comp_compgen [opts] NAME
{ => _comp_compgen}_filedir
and _comp_compgen [opts] NAME
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, very nice!
I did not look into usages yet, but I thought I'd just ask -- in the vast majority of cases we have I believe _filedir
's behavior of appending to COMPREPLY
isn't required and we could replace instead. Usually superflous append does no harm either though, because COMPREPLY
is in most cases empty at that time. What do you think, while we're working on this, should we also review each call site and remove the append behavior where unnecessary? I think doing so would reveal and fix some bugs, but this is quite a bit of work for a smallish gain. We can also postpone to later if seen useful but not something we'd like to do now.
I agree with it, but we need to carefully check each case not to break existing behavior. In removing flag
Actually, at the current stage, the new implementation of |
a0ea8d2
to
3813c29
Compare
The function bash-completion/completions/lintian Lines 70 to 145 in a26a2a9
Even when completions are generated in diff --git a/completions/lintian b/completions/lintian
index 0769fb4b..2175c720 100644
--- a/completions/lintian
+++ b/completions/lintian
@@ -89,28 +89,36 @@ _comp_cmd_lintian()
case $prev in
-C | --check-part | -X | --dont-check-part)
_comp_cmd_lintian__checks
+ return
;;
-T | --tags | --suppress-tags)
_comp_cmd_lintian__tags
+ return
;;
--tags-from-file | --suppress-tags-from-file | --cfg | -p | \
--packages-file)
_filedir
+ return
;;
--lab | --archivedir | --dist | --root)
_filedir -d
+ return
;;
--color)
COMPREPLY=($(compgen -W "never always auto html" -- "$cur"))
+ return
;;
-U | --unpack-info)
_comp_cmd_lintian__infos
+ return
;;
--area | --section)
COMPREPLY=($(compgen -W "main contrib non-free" -- "$cur"))
+ return
+ ;;
+ --arch)
+ return
;;
- --arch) ;;
-
esac
fi |
The function bash-completion/completions/python Lines 64 to 74 in a26a2a9
Case |
5237ef9
to
52e6547
Compare
This branch of bash-completion/completions/smartctl Lines 55 to 57 in a26a2a9
|
It is subtle whether to make bash-completion/completions/ssh Lines 251 to 261 in a26a2a9
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff. Left a few comments inline in response to separate comments, pre-approved with them addressed the way you see best.
The directory names are generated by default with `_filedir` and `_filedir ext`, so an independent `_filedir -d` would not be needed.
0778324
to
7035f5f
Compare
Partly squashed |
I came up with a new idea for #948 (comment). This PR implements the idea using
_filedir
as an example._filedir
is renamed to_comp_compgen_filedir
. This function can be directly called by_comp_compgen_filedir ...
as we have been doing so far but can also be called as_comp_compgen filedir ...
.In the above,
_comp_compgen
redirects the call_comp_compgen NAME
to the shell function_comp_compgen_NAME
in a similar way asxfunc
. Note that this is not ambiguous with the call_comp_compgen -- <comgpen args>
because all the arguments to thecompgen
builtin start with-
while our function names do not contain-
. When the first (non-option) argument of_comp_compgen
does not start with-
,_comp_compgen
redirects the call to"_comp_compgen_$1"
. Otherwise, _comp_compgen can consider the arguments to be passed to thecompgen
builtin._comp_compgen
will take effect in the behavior of the redirected_comp_compgen_filedir
. For example,_comp_compgen_filedir
stores the result inCOMPREPLY
by default, but we can instead store the results to a specified arrayarr
by_comp_compgen -v arr filedir
. This is done by recording the parsed options in local variables_comp_compgen__*
and letting the child calls of_comp_compgen
inside_comp_compgen_filedir
reference the local variables.Commit fcf9825 implements the above two extensions of
_comp_compgen
. Actually, the implementation is simple.The modification at the
_filedir
side is minimal as far as the completions are generated through_comp_compgen
. Only the codes that directly referencecur
andCOMPREPLY
need to be updated.edit: I also changed the behavior of
_comp_compgen_filedir
so that it replaces the existingCOMPREPLY
by default. To make it append to the array, one can specify the-a
option as_comp_compgen -a filedir
. Currently, many similar functions just replace the existing contents, but only a part of them try to append to the array. I'd like to make the default behaviors of similar functions consistent and allow appending as an option-a
.