-
Notifications
You must be signed in to change notification settings - Fork 0
More flexible shell completion #146
Comments
Comment by pksunkara We are always open to PRs. I am not exactly good at the completion scripts. I couldn't even get zsh running locally 😞 |
Comment by d-e-s-o My bash completion days are also behind me (and I happily flushed 90% I knew from memory). That being said, this patch seems to be doing the trick: --- src/completions/bash.rs
+++ src/completions/bash.rs
@@ -33,8 +33,8 @@ impl<'a, 'b> BashGen<'a, 'b> {
for i in ${{COMP_WORDS[@]}}
do
case "${{i}}" in
- {name})
- cmd="{name}"
+ "${{1}}")
+ cmd="${{1}}"
;;
{subcmds}
*)
@@ -43,7 +43,7 @@ impl<'a, 'b> BashGen<'a, 'b> {
done
case "${{cmd}}" in
- {name})
+ "${{1}}")
opts="{name_opts}"
if [[ ${{cur}} == -* || ${{COMP_CWORD}} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${{opts}}" -- "${{cur}}") ) I'll probably open a PR unless I find an issue... |
Comment by pickfire I believe this is fixed. |
Comment by d-e-s-o
Mind sharing details as to why you believe that to be the case? |
Comment by pickfire Because there was a pull request for it? Ah, I didn't notice it was closed instead of merged. |
Comment by pksunkara And it was closed without merging because it didn't actually fix the issue. |
Issue by d-e-s-o
Thursday Mar 26, 2020 at 21:05 GMT
Originally opened as clap-rs/clap#1764
It would be great if the shell completion was more flexible in what commands it applies to. Let's say I have a program
foo
and a completion scriptfoo.bash
as generated byclap
. If I sourcefoo.bash
I now have completion forfoo
's arguments. Fine.However, what if I have aliased
f
tofoo
? Naturally, I'd want to have completion forf
as well. Usually that's not a problem. The completion script just registers the completion functionality for a certain command. E.g.,complete -F _foo -o bashdefault -o default foo
can be found in
foo.bash
.Unfortunately, though, just changing that to
complete -F _foo -o bashdefault -o default f
doesn't work, because, well, the script itself has the command/name coded into its logic.
That doesn't have to be the case, however, as
git
for example shows. Here all I have to do is register my alias as follows:and bam,
g
has completion.Would be great to have such a more flexible completion script.
The text was updated successfully, but these errors were encountered: