Skip to content

Commit

Permalink
Add missing compdef call
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Cornelius Weig committed Oct 27, 2019
1 parent 5fd329a commit b485582
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package cmd

import (
"fmt"
"io"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -38,6 +40,8 @@ const (
Additionally, you may want to output the completion to a file and source in your .bashrc
`

zshCompdef = "\ncompdef _rakkess rakkess\n"
)

var completionCmd = &cobra.Command{
Expand All @@ -58,7 +62,7 @@ var completionCmd = &cobra.Command{
case "bash":
err = rootCmd.GenBashCompletion(out)
case "zsh":
err = rootCmd.GenZshCompletion(out)
err = getZshCompletion(out)
}
if err != nil {
logrus.Fatal(err)
Expand All @@ -69,3 +73,11 @@ var completionCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(completionCmd)
}

func getZshCompletion(out io.Writer) error {
if err := rootCmd.GenZshCompletion(out); err != nil {
return err
}
_, err := io.WriteString(out, zshCompdef)
return err
}

0 comments on commit b485582

Please sign in to comment.