Skip to content

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
@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
@akinomyoga akinomyoga marked this pull request as ready for review June 17, 2025 22:06
Copy link
Owner

@scop scop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Pre-approved with one tiny suggestion.

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.

Co-authored-by: Ville Skyttä <[email protected]>
* 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:*.*`
@scop scop merged commit b6d4335 into scop:main Aug 10, 2025
7 checks passed
@akinomyoga akinomyoga deleted the _comp_compgen-P branch August 10, 2025 10:51
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.

2 participants