diff --git a/.github/workflows/wc-integration-test.yaml b/.github/workflows/wc-integration-test.yaml index 0c725cd57..0518f0561 100644 --- a/.github/workflows/wc-integration-test.yaml +++ b/.github/workflows/wc-integration-test.yaml @@ -149,6 +149,8 @@ jobs: run: aqua completion bash - name: output zsh completion run: aqua completion zsh + - name: output fish completion + run: aqua completion fish - run: aqua g -i suzuki-shunsuke/tfcmt working-directory: tests/main diff --git a/.goreleaser.yml b/.goreleaser.yml index 4da298fea..bbe160079 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -82,7 +82,7 @@ brews: # Template: allowed # Since: v1.20 extra_install: | - generate_completions_from_executable(bin/"aqua", "completion", shells: [:bash, :zsh]) + generate_completions_from_executable(bin/"aqua", "completion", shells: [:bash, :zsh, :fish]) scoops: - diff --git a/pkg/cli/completion.go b/pkg/cli/completion.go index 6792fd6cf..30dd9c6d2 100644 --- a/pkg/cli/completion.go +++ b/pkg/cli/completion.go @@ -11,17 +11,27 @@ func (r *Runner) newCompletionCommand() *cli.Command { // https://cli.urfave.org/v2/#bash-completion return &cli.Command{ Name: "completion", - Usage: "Output shell completion script for bash or zsh", - Description: `Output shell completion script for bash or zsh -Run these commands in .bash_profile or .zprofile + Usage: "Output shell completion script for bash, zsh, or fish", + Description: `Output shell completion script for bash, zsh, or fish +Run these commands in .bash_profile, .zprofile, or ~/.config/config.fish. e.g. .bash_profile -if command -v aqua &> /dev/null; then source <(aqua completion bash); fi +if command -v aqua &> /dev/null; then + source <(aqua completion bash) +fi .zprofile -if command -v aqua &> /dev/null; then source <(aqua completion zsh); fi +if command -v aqua &> /dev/null; then + source <(aqua completion zsh) +fi + +~/.config/config.fish + +if command -v aqua &> /dev/null; + aqua completion fish | source +end `, Subcommands: []*cli.Command{ { @@ -34,6 +44,11 @@ if command -v aqua &> /dev/null; then source <(aqua completion zsh); fi Usage: "Output shell completion script for zsh", Action: r.zshCompletionAction, }, + { + Name: "fish", + Usage: "Output shell completion script for fish", + Action: r.fishCompletionAction, + }, }, } } @@ -90,3 +105,12 @@ else fi`) return nil } + +func (r *Runner) fishCompletionAction(c *cli.Context) error { + s, err := c.App.ToFishCompletion() + if err != nil { + return fmt.Errorf("generate fish completion: %w", err) + } + fmt.Fprintln(r.Stdout, s) + return nil +}