Skip to content

Commit 38a327a

Browse files
committed
Add fish shell completion
Signed-off-by: Yutaro Suzuki <[email protected]>
1 parent 577d2c8 commit 38a327a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

cmd/completion/completion.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/spf13/cobra"
1515

1616
"github.com/terraform-docs/terraform-docs/cmd/completion/bash"
17+
"github.com/terraform-docs/terraform-docs/cmd/completion/fish"
1718
"github.com/terraform-docs/terraform-docs/cmd/completion/zsh"
1819
)
1920

@@ -22,18 +23,19 @@ func NewCommand() *cobra.Command {
2223
cmd := &cobra.Command{
2324
Args: cobra.NoArgs,
2425
Use: "completion SHELL",
25-
Short: "Generate shell completion code for the specified shell (bash or zsh)",
26+
Short: "Generate shell completion code for the specified shell (bash,zsh,fish)",
2627
Long: longDescription,
2728
}
2829

2930
// subcommands
3031
cmd.AddCommand(bash.NewCommand())
3132
cmd.AddCommand(zsh.NewCommand())
33+
cmd.AddCommand(fish.NewCommand())
3234

3335
return cmd
3436
}
3537

36-
const longDescription = `Outputs terraform-doc shell completion for the given shell (bash or zsh)
38+
const longDescription = `Outputs terraform-doc shell completion for the given shell (bash,zsh,fish)
3739
This depends on the bash-completion binary. Example installation instructions:
3840
# for bash users
3941
$ terraform-doc completion bash > ~/.terraform-doc-completion
@@ -45,6 +47,9 @@ This depends on the bash-completion binary. Example installation instructions:
4547
# or if zsh-completion is installed via homebrew
4648
% terraform-doc completion zsh > "${fpath[1]}/_terraform-doc"
4749
50+
# for fish users
51+
$ terraform-doc completion fish | source
52+
4853
Additionally, you may want to output the completion to a file and source in your .bashrc
4954
Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
5055
`

cmd/completion/fish/fish.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2021 The terraform-docs Authors.
3+
4+
Licensed under the MIT license (the "License"); you may not
5+
use this file except in compliance with the License.
6+
7+
You may obtain a copy of the License at the LICENSE file in
8+
the root directory of this source tree.
9+
*/
10+
11+
package fish
12+
13+
import (
14+
"os"
15+
16+
"github.com/spf13/cobra"
17+
)
18+
19+
// NewCommand returns a new cobra.Command for 'completion fish' command
20+
func NewCommand() *cobra.Command {
21+
cmd := &cobra.Command{
22+
Args: cobra.NoArgs,
23+
Use: "fish",
24+
Short: "Generate shel completion for fish",
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
return cmd.Parent().Parent().GenFishCompletion(os.Stdout, true)
27+
},
28+
}
29+
return cmd
30+
}

0 commit comments

Comments
 (0)