-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dynamic completion at intermediate position erroneously completes the following argument on bash and zsh #5979
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
2 tasks done
Labels
A-completion
Area: completion generator
C-bug
Category: bug
S-waiting-on-design
Status: Waiting on user-facing design to be resolved before implementing
Comments
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-completion
Area: completion generator
C-bug
Category: bug
S-waiting-on-design
Status: Waiting on user-facing design to be resolved before implementing
Please complete the following tasks
Rust Version
rustc 1.86.0 (05f9846f8 2025-03-31)
Clap Version
clap 4.5.37 / clap_complete 4.5.47
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo build
.Replace
~/.cargo/target/debug/clap-complete-minimal
with the path to the executable.3. Type the following line in your shell, then move the caret to the designated position and hit tab to trigger completion:
Actual Behaviour
On fish, only the
--
common to all flags is completed and the user is presented with a choice between all four flags (including--help
):On bash and zsh,
--ba
is inserted. This is the same result that one would get when completing--b
, i.e. only--bar
and--baz
are eligible and--ba
is completed as their common prefix. However, here the completion does not replace the existing--b
token; it is inserted as a new token at the caret position:$ ~/.cargo/target/debug/clap-complete-minimal --ba --b
Expected Behaviour
The fish behavior seems pretty reasonable and I would expect bash/zsh to behave the same way. In any case, it seems desirable for all shells to be as close as possible in completion behavior.
Additional Context
The bash glue script only forwards
COMP_WORDS
andCOMP_CWORD
to the completer.COMP_WORDS
does not include an empty "word" when completions are triggered and intermediate positions, so from this information alone, it is not possible to distinguish a completion at an intermediate position from one of the subsequent argument. The same apparently holds for zsh. Relevant design discussion: #5512This problem should affect pretty much any CLI using dynamic completions. I encountered it when working on tests for Jujutsu's completions. See also the discussion on jj-vcs/jj#6407 (comment).
Debug Output
Bash:
Fish:
(Zsh swallows stderr when triggering completions.)
The text was updated successfully, but these errors were encountered: