Skip to content

feat(_comp_compgen): support -P prefix with adjusted cur #1360

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

akinomyoga
Copy link
Collaborator

See the commit message.

@akinomyoga akinomyoga changed the title feat(_comp_compgen): support -P prefix with adjusted cur [waiting for #1359] feat(_comp_compgen): support -P prefix with adjusted cur Apr 6, 2025
The Bash builtin `compgen -P prefix ... -- "$cur"` prepends the prefix
AFTER filtering completions using `$cur`.  However, we usually want to
filter completions with "$cur" starting with the prefix.

To properly handle such a situation, one first needs to check if the
current content of "$cur" is compatible.  Then, one needs to modify
$cur to remove the prefix part, generate completions, and prepends the
prefix to the generated completions.  This pattern is used frequently
in the codebase, so it is good to handle it within `_comp_compgen`.

This patch implements the option `-P` of `_comp_compgen`.  When a
non-empty string is specified to the `-P` option, it performs the
necessary operations: the check and adjustment of $cur, the proper
filtering by the prefix string, and prepending of the prefix string.
@akinomyoga akinomyoga force-pushed the _comp_compgen-P branch 2 times, most recently from 60ea27f to 00a2be5 Compare June 17, 2025 15:15
@akinomyoga akinomyoga changed the title [waiting for #1359] feat(_comp_compgen): support -P prefix with adjusted cur feat(_comp_compgen): support -P prefix with adjusted cur Jun 17, 2025
* refactor(dot,gprof,protoc,ssh,7z): use `_comp_compgen -P` for optargs
* refactor(_comp_compgen_tilde): use `_comp_compgen -P` for `~...`
* refactor(curl,strings): use `_comp_compgen -P` for `@...`
* refactor(tshark): use `_comp_compgen -P` for `-[oX]-...`
* refactor({,u}mount,kcov,lintian): use `_comp_compgen -P` for `*,*`
* refactor(upgradepkg): use `_comp_compgen -P` for `*%*`
* refactor(_mount{,.linux}): use `_comp_compgen -P` for `//host/...`
* refactor(xgamma): use `_comp_compgen -P` for `-display:*.*`
@akinomyoga akinomyoga marked this pull request as ready for review June 17, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant