Skip to content

Commit

Permalink
add fish shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
WLun001 committed Jul 11, 2020
1 parent f49b40c commit bf46809
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
22 changes: 16 additions & 6 deletions cli/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ func newCmdCompletion() *cobra.Command {
source <(linkerd completion zsh)
# zsh on osx / oh-my-zsh
linkerd completion zsh > "${fpath[1]}/_linkerd"`
linkerd completion zsh > "${fpath[1]}/_linkerd"
# Fish:
$ linkerd completion fish | source
# fish To load completions for each session, execute once:
$ linkerd completion fish > ~/.config/fish/completions/linkerd.fish
`

cmd := &cobra.Command{
Use: "completion [bash|zsh]",
Short: "Output shell completion code for the specified shell (bash or zsh)",
Long: "Output shell completion code for the specified shell (bash or zsh).",
Use: "completion [bash|zsh|fish]",
Short: "Output shell completion code for the specified shell (bash, zsh or fish)",
Long: "Output shell completion code for the specified shell (bash, zsh or fish).",
Example: example,
Args: cobra.ExactArgs(1),
ValidArgs: []string{"bash", "zsh"},
ValidArgs: []string{"bash", "zsh", "fish"},
RunE: func(cmd *cobra.Command, args []string) error {
out, err := getCompletion(args[0], cmd.Parent())
if err != nil {
Expand All @@ -62,8 +69,11 @@ func getCompletion(sh string, parent *cobra.Command) (string, error) {
err = parent.GenBashCompletion(&buf)
case "zsh":
err = parent.GenZshCompletion(&buf)
case "fish":
err = parent.GenFishCompletion(&buf, true)

default:
err = errors.New("unsupported shell type (must be bash or zsh): " + sh)
err = errors.New("unsupported shell type (must be bash, zsh or fish): " + sh)
}

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v0.0.5
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1 // indirect
github.com/wercker/stern v0.0.0-20190705090245-4fa46dd6987f
Expand Down
Loading

0 comments on commit bf46809

Please sign in to comment.