Visitar URL original
usage-argv completion scripts: bash doubles a `--flag=` prefix, and the trailing space is wrong in both bash and zsh · Issue #1641 · jdx/usage · GitHub
Skip to content

usage-argv completion scripts: bash doubles a --flag= prefix, and the trailing space is wrong in both bash and zsh #1641

Closed

Description

@powerman

The completion scripts generated by usage-argv
(usage --completions <shell>, mise completion <shell>, any usage-rs CLI)
insert candidates badly, and bash and zsh are wrong in opposite ways.

  1. bash: a value attached with = lands after its own prefix.

    $ usage complete-word --shell=ba<Tab>
    $ usage complete-word --shell=--shell=bash 

    The answer is the full word --shell=bash, but Readline replaces only the text after =,
    which is in the default COMP_WORDBREAKS.
    render_request (argv/src/complete.rs:1117) emits \x01prefix only for : (line 1132).
    It is the bug of Bash completion duplicates colon-prefixed task names on second Tab mise#12970, fixed by fix(bash): preserve colon-prefixed completion words #1405 and fix(completions): trim the colon prefix bash keeps for namespaced task names mise#13276 for : alone.
    The usage-cli scripts trim both (${COMP_WORDBREAKS//[^:=]/}).

  2. bash: a space after every candidate, including those meant to be continued.
    mise use node<Tab> gives mise use node@ ,
    and a complete type="dir" match gives sub/ .
    The script registers with a bare complete -F (argv/src/script.rs:262),
    without the -o nospace which the usage-cli scripts, and mise up to 2026.8, had for exactly
    this reason (Does it make sense to add space after command when auto-completing? mise#4243).
    Paths behind the \x01dirs/\x01files markers are fine thanks to compopt -o filenames.

  3. zsh: no space after any candidate, even a finished one.
    usage gen<Tab> gives usage generate and the cursor stays right after it,
    and the same for every subcommand, flag, choice and complete run= value.
    compadd ... -S '' (argv/src/script.rs:356) comes from fix(zsh): remove trailing space from completions and add directory slash #556,
    which fixed zsh completion adds incorrect spaces #67 (node@, /opt/homebrew/) by dropping the suffix for all candidates.

Expected in both shells: a space after a finished value (generate, --shell=bash, alpha),
none after a partial one (node@, build:, sub/), and --shell=ba<Tab> → --shell=bash.

Repro for 2 and 3 with candidates of a mise task (mkdir -p sub/inner, mise trust):

[tasks.t]
usage = '''
flag "--c <c>" { choices "alpha" "beta"; }
flag "--d <d>" { complete type="dir"; }
'''
run = 'echo "$@"'
Typed bash zsh
mise ru<Tab> mise run ✓ mise run (no space)
mise run t --c al<Tab> --c alpha ✓ --c alpha (no space)
mise run t --c=al<Tab> --c=--c=alpha --c=alpha (no space)
mise run t --d su<Tab> --d sub/ (space) --d sub/ ✓
mise use node<Tab> mise use node@ (space) mise use node@ ✓

Found while building kongusage (https://github.com/powerman/kongusage, a Kong → usage spec
exporter), which emits choices and complete type=… so that mise tasks complete better than
with the shell's file completion; with these bugs they complete worse.

Reproduced in real bash 5.3 and zsh 5.9 with usage 7.3.0 and main (220ffb2),
and with mise 2026.11.0 (usage-argv 7.3.0, as in mise 2026.11.6 and main).

AI-assisted — Tool: Claude Code; model: anthropic/claude-opus-5-5; version: 2.1.318.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions