Closed Ordoviz closed 11 months ago
Here's what works:
for path in ~/.config/complgen/*.usage; do
stem=$(basename "$path" .usage)
eval "
_complgen_jit_$stem () {
local words cword
_get_comp_words_by_ref -n = words cword
local prefix="\${words[\$cword]}"
local -a completions=(\$(complgen complete \"$HOME/.config/complgen/${stem}.usage\" bash --prefix="\$prefix" -- \${words[@]:1:\$cword-1}))
for item in "\${completions[@]}"; do
if [[ \$item = "\${prefix}"* ]]; then
COMPREPLY+=("\$item")
fi
done
__ltrim_colon_completions "\$prefix"
return 0
}
"
complete -o nospace -F _complgen_jit_$stem "$stem"
unset stem
done
Thanks for reporting!
Still broken: mygrep --color=n<TAB>
completes to mygrep --color=--color=never
.
I have built using cargo build
from latest commit and tested with bash --noprofile --norc -i; source /usr/share/bash-completion/bash_completion
.
Take another look please, it should work better now: https://github.com/adaszko/complgen/blob/4927e628c54244114a7d9d691a125333f9eeaafc/README.md#bash-integration
We are getting there. These autocomplete correctly now:
mygrep <TAB>
mygrep --color=<TAB>
mygrep --color=a<TAB>
mygrep --color=al<TAB>
but mygrep --color
completes to mygrep =
mygrep --color<TAB>
works on my end:
To be clear, I'm talking about the JIT mode, with Bash and complgen at commit 4927e628c54244114a7d9d691a125333f9eeaafc. Perhaps you're at some older commit?
I was using this grammar: https://github.com/adaszko/complgen/blob/4927e628c54244114a7d9d691a125333f9eeaafc/e2e/bash/test_bash_shell_integration.py#L61-L62
Changing it to
mygrep --color=<WHEN>;
<WHEN> ::= always | never | auto;
fixes the bug.
Check again please. The issue was Bash weirdness to do with handling $COMP_WORDBREAKS
characters in completions (=
and :
are among which). Special filtering needs to be performed then to get correct results. I did that for shell script output in the past but seem to have forgotten about it for the JIT mode.
Tested again. Now it's fixed!
Consider this grammar from the e2e tests:
If I save this to
/tmp/mygrep.usage
and source the Bash integration from the READMEit will autocomplete up to
mygrep --color=
but doesn't suggestalways
ornever
.I believe the output from (or the invocation of)
complgen complete
needs to be adjusted to fix this, but I don't actually know. The PR #33 does NOT fix this.Compiling the grammar into a Bash script and sourcing that works fine.