Skip to content

Bash complete unstable-dynamic add **COMP_WORDBREAKS** #6280

@feraxhp

Description

@feraxhp

Please complete the following tasks

Clap Version

clap complete = "4.5.66"

Describe your use case

well i am writing a cli app which receives a parameter that follows this syntax "<config>:<user>/<repo>", the main problem here is in the completion part, because in bash the COMP_WORDBREAKS splits my argument like: "<config>" ":" "<user>" so the completer does not call the completer for that argument...

i figured out that in order to solve this problem i just needed to add this to the completer text generated for bash:

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    COMP_WORDBREAKS=${COMP_WORDBREAKS//:} complete -o nospace -o bashdefault -o nosort -F _clap_complete_grp dgrp
  # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----> this was added by hand
else
    COMP_WORDBREAKS=${COMP_WORDBREAKS//:} complete -o nospace -o bashdefault -F _clap_complete_grp dgrp
fi

Describe the solution you'd like

it may be convenient to have an additional method for CompleteEnv where you can tell it to allow some special character

example

async fn main() {
    // Completitions managger
    clap_complete::CompleteEnv::with_factory(grp::command)
                   .allows(':') // one or various
                   .complete();
    
    // Read actual command
}

the method allows will generate in the bash completion the COMP_WORDBREAKS=${COMP_WORDBREAKS//:} to allow those characters.

Alternatives, if applicable

i have not found a better alternative. i think this is the best approach.

Additional Context

Yes, i other shells, at least in my understanding, do not have this problem. especially with the ':' character.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionArea: completion generatorC-enhancementCategory: Raise on the bar on expectationsS-triageStatus: New; needs maintainer attention.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions