fix(complete): Handle COMP_WORDBREAKS in Bash completion#6264
Open
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Open
fix(complete): Handle COMP_WORDBREAKS in Bash completion#6264AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
AndreasBackx wants to merge 2 commits intoclap-rs:masterfrom
Conversation
The Bash registration script does not currently handle COMP_WORDBREAKS, which causes double-prefixing when completing values containing = or :.
Add prefix-stripping logic to the Bash registration script to prevent double-prefixing when COMP_WORDBREAKS contains = or :.
3635967 to
df24ba0
Compare
epage
reviewed
Feb 13, 2026
| !script.contains("COMP_WORDBREAKS"), | ||
| "registration script does not yet reference COMP_WORDBREAKS" | ||
| ); | ||
| } |
Member
There was a problem hiding this comment.
Please test behavior, not implementation
epage
reviewed
Feb 13, 2026
| #[cfg(all(unix, feature = "unstable-dynamic"))] | ||
| #[cfg(feature = "unstable-shell-tests")] | ||
| fn fish_env_completer_path_quoting_works() { | ||
| use snapbox::assert_data_eq; |
Member
There was a problem hiding this comment.
Why is this being added in this commit
2 tasks
|
i think u must implement a method to allow personalize the behavior, because not every cli tool will need = or : or any other character. Something similar to the proposal of #6280 |
scutuatua-crypto
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #3920
Summary
Adds COMP_WORDBREAKS prefix-stripping to the Bash registration script to prevent double-prefixing
when completing values containing
=or:.When
=is in COMP_WORDBREAKS (the default), Bash splits--flag=valueinto separate words at=. Without this fix, the completion function returns--flag=valuebut Bash only replaces the part after=, producing--flag=--flag=value.The fix uses the standard approach (also used by git, docker, aws-cli): strip the prefix up to the last word-break character from each COMPREPLY entry.
Changes
clap_complete/src/env/shells.rs: Added prefix-stripping block to Bash registration script template + unit test asserting the handling exists.Note on testing
This fix is in the shell registration script (Bash code), not in the Rust completion engine. It cannot be unit-tested without a real Bash shell. The existing PTY-based test
complete_dynamic_env_option_valueinbash.rsexercises--choice=completion through a real shell and would catch regressions. The unit test verifies the registration script contains the COMP_WORDBREAKS handling logic.Test plan
cargo test -p clap_complete --features unstable-dynamic— all tests passcargo clippy -p clap_complete --features unstable-dynamic— clean