Skip to content

Add shell auto-completion support for Bash, Fish and Zsh #718

@braph

Description

@braph

Hello,

I'm the author of crazy-complete and I've started working on a completion definition for legendary.

I know there are already two open issues about Bash completion, but the completions proposed there are not as fine-grained as mine.

You can find the definition file as well as pre-generated auto-completion files here inside the legendary directory.

Here's how you can try out the scripts:

  • bash: source ./generated/bash/legendary
  • fish: source ./generated/fish/legendary.fish
  • zsh: source ./generated/zsh/legendary.sourceable

The definition file is still a work in progress and has some gaps: In a few places I wasn't always
sure what the completion should be (e.g. whether an option should complete to a file or directory).
These spots are marked with # TODO comments in the definition file.

Here are some details about the setup:

  • The completion files are currently built via the Makefile.
    The following arguments are passed to crazy-complete:

    • --include-file=: Includes additional files into the generated output.
      These contain helper functions used by crazy-complete.
    • --inherit-options=True: Ensures that subcommands also inherit the options
      of their parent command.
  • Some directives inside legendary.yaml worth clarifying:

    • final: true: Marks an option as final, meaning no more options may follow it.
    • groups: [...]: Defines mutually exclusive groups of options.
    • complete: ['exec', '<function>']: Executes function and uses its output for completing.
    • complete: ['combine', [...]]: Combines multiple completers into one.
    • complete: ['choices', [...]]: Complete from a fixed list of words.
    • complete: ['none']: Marks an option as taking an argument but without a completer.

Feedback and contributions, especially towards resolving the TODOs in the definition file, would be very welcome!

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