Skip to content

Comments

contrib/completion/zsh: add CLI plugin completion support#6811

Open
4RH1T3CT0R7 wants to merge 1 commit intodocker:masterfrom
4RH1T3CT0R7:6231-zsh-completion-cli-plugins
Open

contrib/completion/zsh: add CLI plugin completion support#6811
4RH1T3CT0R7 wants to merge 1 commit intodocker:masterfrom
4RH1T3CT0R7:6231-zsh-completion-cli-plugins

Conversation

@4RH1T3CT0R7
Copy link

- What I did

Added zsh completion support for Docker CLI plugins (compose, buildx, scout, etc.) by implementing the Cobra __completeNoDesc shell completion protocol.

Previously, docker <TAB> would list plugin commands, but docker compose <TAB> produced no completions because __docker_subcommand() had no handler for CLI plugins.

- How I did it

Added three components to contrib/completion/zsh/_docker:

  1. __docker_cli_plugin_path() — discovers plugin binary paths from docker info output, with results cached using zsh's _store_cache/_retrieve_cache (1-hour TTL matching __docker_commands)

  2. __docker_complete_cli_plugin() — invokes the plugin binary with __completeNoDesc and processes the response, handling all six Cobra ShellCompDirective values:

    • Error (1): abort completion
    • NoSpace (2): suppress trailing space
    • NoFileComp (4): suppress file fallback
    • FilterFileExt (8): filter files by extension
    • FilterDirs (16): complete directories only
    • KeepOrder (32): preserve completion ordering
  3. A (*) fallback case in __docker_subcommand() that delegates to the plugin binary when the command matches a known plugin.

Additional details:

  • ActiveHelp markers displayed as informational text via compadd -x
  • Literal colons escaped for _describe separator
  • --flag=<TAB> completions propagate the flag prefix correctly
  • Words truncated to CURRENT for backward cursor movement support
  • Modeled after vendor/github.com/spf13/cobra/zsh_completions.go and the existing bash plugin completion in contrib/completion/bash/docker

- How to verify it

  1. Install a CLI plugin (e.g., compose or buildx)
  2. Source the updated completion: source contrib/completion/zsh/_docker
  3. Type docker compose <TAB> — should show compose subcommands
  4. Type docker compose up --<TAB> — should show compose flags
  5. Type docker buildx build <TAB> — should show buildx completions

- Human readable description for the release notes

Add zsh shell completion support for Docker CLI plugins (compose, buildx, etc.)

Closes #6231

@4RH1T3CT0R7 4RH1T3CT0R7 force-pushed the 6231-zsh-completion-cli-plugins branch from 7409672 to 12382f1 Compare February 21, 2026 20:35
Previously, the zsh completion script could list Docker CLI plugin
commands (compose, buildx, etc.) via __docker_commands(), but had no
handler in __docker_subcommand() for them. This meant that while
"docker <TAB>" would show "compose" as an option, "docker compose <TAB>"
produced no completions.

Add support for CLI plugin completion by invoking the plugin binary's
Cobra __completeNoDesc protocol, similar to how the bash completion
already handles this.

The implementation handles all six Cobra ShellCompDirective values:
  - Error (1): abort completion
  - NoSpace (2): suppress trailing space
  - NoFileComp (4): suppress file fallback
  - FilterFileExt (8): filter files by extension
  - FilterDirs (16): complete directories only
  - KeepOrder (32): preserve completion ordering

Additionally:
- Plugin paths are cached using zsh's _store_cache/_retrieve_cache
  with the same 1-hour TTL policy as __docker_commands
- ActiveHelp markers are displayed as informational text
- Literal colons in completions are escaped for _describe
- --flag=<TAB> completions propagate the flag prefix correctly
- Words are truncated to CURRENT for backward cursor movement

Closes: docker#6231

Signed-off-by: 4RH1T3CT0R7 <iprintercanon@gmail.com>
@4RH1T3CT0R7 4RH1T3CT0R7 force-pushed the 6231-zsh-completion-cli-plugins branch from 12382f1 to c765db0 Compare February 21, 2026 20:38
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.

contrib/completion/zsh doesn't complete compose

1 participant