Files
gems/opal-task/cmd/completion.go
T
joakim 3c0d4ee471 fix: use proper zsh/bash completion methods and correct zsh install instructions
Use GenZshCompletion (native zsh) instead of the old bash-wrapper method.
Use GenBashCompletionV2 for modern bash completions. Fix help text to show
proper fpath-based zsh installation instead of `source`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 15:08:27 +01:00

56 lines
1.4 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate shell completions",
Long: `Generate shell completion scripts for opal.
To load completions:
Bash:
$ source <(opal completion bash)
# To load on startup, add to ~/.bashrc:
$ echo 'source <(opal completion bash)' >> ~/.bashrc
Zsh:
# Option 1: Write to a directory in your $fpath
$ opal completion zsh > "${fpath[1]}/_opal"
# Then restart your shell or run: compinit
# Option 2: Write to a custom directory and add it to fpath
$ mkdir -p ~/.zsh/completions
$ opal completion zsh > ~/.zsh/completions/_opal
# Add to ~/.zshrc (before compinit):
# fpath=(~/.zsh/completions $fpath)
# autoload -Uz compinit && compinit
Fish:
$ opal completion fish | source
# To load on startup:
$ opal completion fish > ~/.config/fish/completions/opal.fish`,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
rootCmd.GenBashCompletionV2(os.Stdout, true)
case "zsh":
rootCmd.GenZshCompletion(os.Stdout)
case "fish":
rootCmd.GenFishCompletion(os.Stdout, true)
case "powershell":
rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
default:
fmt.Fprintf(os.Stderr, "Unknown shell: %s\n", args[0])
os.Exit(1)
}
},
}