Skip to content

Commit b485582

Browse files
author
Cornelius Weig
committed
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 5fd329a commit b485582

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

cmd/completion.go

Lines changed: 13 additions & 1 deletion
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)