Skip to content

[Feature] Shell completions (Bash, Zsh, Fish, PowerShell) #26

@Siddhant-K-code

Description

@Siddhant-K-code

Summary

Add distill completion command that generates shell completions for Bash, Zsh, Fish, and PowerShell.

Motivation

Shell completions are a low-effort, high-polish feature that signals CLI maturity. Cobra provides built-in support.

Implementation

Cobra has built-in completion generation. Add a completion command:

// cmd/completion.go
var completionCmd = &cobra.Command{
    Use:   "completion [bash|zsh|fish|powershell]",
    Short: "Generate shell completion scripts",
    Long: `Generate shell completion scripts for Distill CLI.

Bash:
  $ distill completion bash > /etc/bash_completion.d/distill

Zsh:
  $ distill completion zsh > "${fpath[1]}/_distill"

Fish:
  $ distill completion fish > ~/.config/fish/completions/distill.fish

PowerShell:
  PS> distill completion powershell | Out-String | Invoke-Expression`,
    ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
    Args:      cobra.ExactArgs(1),
    RunE: func(cmd *cobra.Command, args []string) error {
        switch args[0] {
        case "bash":
            return rootCmd.GenBashCompletion(os.Stdout)
        case "zsh":
            return rootCmd.GenZshCompletion(os.Stdout)
        case "fish":
            return rootCmd.GenFishCompletion(os.Stdout, true)
        case "powershell":
            return rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
        }
        return fmt.Errorf("unsupported shell: %s", args[0])
    },
}

Deliverables

  • cmd/completion.go - Completion command
  • README section with installation instructions per shell
  • GoReleaser: include completion scripts in release archives

Acceptance Criteria

  • distill completion bash outputs valid bash completion
  • distill completion zsh outputs valid zsh completion
  • Tab-completing distill se<TAB> yields serve
  • Flag completions work (e.g., distill api --p<TAB> yields --port)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions