Skip to content

Commit eb1ac91

Browse files
Cornelius Weigcorneliusweig
Cornelius Weig
authored andcommitted
Add missing compdef call
The vanilla version assumes that the completion script is generated once and then put in the zsh completion script folder. This has advantages, such as better caching, but it breaks the most common use-case `source <(rakkess completion zsh)` This commit adds a compdef call which re-enables this usage. Also see spf13/cobra#887
1 parent f857468 commit eb1ac91

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

cmd/completion.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package cmd
1818

1919
import (
2020
"fmt"
21+
"io"
22+
2123
"github.com/sirupsen/logrus"
2224
"github.com/spf13/cobra"
2325
)
@@ -38,6 +40,8 @@ const (
3840
3941
Additionally, you may want to output the completion to a file and source in your .bashrc
4042
`
43+
44+
zshCompdef = "\ncompdef _rakkess rakkess\n"
4145
)
4246

4347
var completionCmd = &cobra.Command{
@@ -58,7 +62,7 @@ var completionCmd = &cobra.Command{
5862
case "bash":
5963
err = rootCmd.GenBashCompletion(out)
6064
case "zsh":
61-
err = rootCmd.GenZshCompletion(out)
65+
err = getZshCompletion(out)
6266
}
6367
if err != nil {
6468
logrus.Fatal(err)
@@ -69,3 +73,11 @@ var completionCmd = &cobra.Command{
6973
func init() {
7074
rootCmd.AddCommand(completionCmd)
7175
}
76+
77+
func getZshCompletion(out io.Writer) error {
78+
if err := rootCmd.GenZshCompletion(out); err != nil {
79+
return err
80+
}
81+
_, err := io.WriteString(out, zshCompdef)
82+
return err
83+
}

0 commit comments

Comments
 (0)