Skip to content

feat(cli): add shell completion support (bash, zsh, fish) #315

Closed

Description

@margaretjgu

Summary

elastic <TAB> produces no completions today. With 500+ ES subcommands across multiple namespaces, shell completion is essential for discoverability and day-to-day usability before public launch.

Proposed UX

Following the gh / kubectl convention -- a completion subcommand that prints a sourcing script to stdout:

elastic completion bash   >> ~/.bashrc
elastic completion zsh    >> ~/.zshrc
elastic completion fish   > ~/.config/fish/completions/elastic.fish

Post-install docs can show:

# zsh
echo 'source <(elastic completion zsh)' >> ~/.zshrc

# bash
echo 'source <(elastic completion bash)' >> ~/.bashrc

Implementation notes

Commander v14 ships generateCompletion() which emits a completion script for the registered command tree. This should cover the top-level commands automatically.

The main challenge is the lazy-loaded command trees (stack es, stack kb, etc.) -- completions for those namespaces will only be accurate if the full command tree is registered before generateCompletion() is called. The completion command should force-load all lazy subtrees before generating.

The extension subtree is dynamic (installed extensions vary per user) -- completion for extension names can be generated by reading ~/.elastic/extensions.json at completion time.

Acceptance criteria

  • elastic completion zsh prints a valid zsh completion script
  • elastic completion bash prints a valid bash completion script
  • elastic completion fish prints a valid fish completion script
  • Top-level commands (stack, cloud, config, extension, docs, sanitize) all complete
  • ES/KB namespace commands complete (e.g. elastic es ind<TAB> -> indices)
  • Installed extension names complete as top-level commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgood first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions