Skip to content

Commit

Permalink
fix: Don't complete _chezmoi in zsh completion
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 18, 2022
1 parent f25a01c commit 7485aea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion completions/chezmoi.zsh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion pkg/cmd/completioncmd.go
Expand Up @@ -31,27 +31,35 @@ func (c *Config) newCompletionCmd() *cobra.Command {
func (c *Config) runCompletionCmd(cmd *cobra.Command, args []string) error {
builder := strings.Builder{}
builder.Grow(16384)
var output string
switch args[0] {
case "bash":
includeDesc := true
if err := cmd.Root().GenBashCompletionV2(&builder, includeDesc); err != nil {
return err
}
output = builder.String()
case "fish":
includeDesc := true
if err := cmd.Root().GenFishCompletion(&builder, includeDesc); err != nil {
return err
}
output = builder.String()
case "powershell":
if err := cmd.Root().GenPowerShellCompletion(&builder); err != nil {
return err
}
output = builder.String()
case "zsh":
if err := cmd.Root().GenZshCompletion(&builder); err != nil {
return err
}
// FIXME remove the following when
// https://github.com/spf13/cobra/pull/1690 is merged and released
output = "#compdef chezmoi\n" + strings.TrimPrefix(builder.String(), "#compdef _chezmoi chezmoi\n")

default:
return fmt.Errorf("%s: unsupported shell", args[0])
}
return c.writeOutputString(builder.String())
return c.writeOutputString(output)
}
2 changes: 1 addition & 1 deletion pkg/cmd/testdata/scripts/completion.txt
Expand Up @@ -12,4 +12,4 @@ stdout 'Register-ArgumentCompleter'

# test that chezmoi completion zsh generates zsh completions
chezmoi completion zsh
stdout '#compdef _chezmoi chezmoi'
stdout '#compdef chezmoi'

0 comments on commit 7485aea

Please sign in to comment.