diff --git a/completions_zsh.go b/completions_zsh.go index 6c12903..3f0d286 100644 --- a/completions_zsh.go +++ b/completions_zsh.go @@ -15,7 +15,6 @@ func WriteZshCompletions(out io.Writer, rootCmd *Command) error { } // TODO: Fix indentation and other spacing -// TODO: Implement global options var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(` {{- $rootCmd := .RootCmd -}} {{- $progName := $rootCmd.Name -}} @@ -39,8 +38,12 @@ var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(` _arguments {{- end -}} {{- range .Cmd.Opts -}} - {{ " " }}\ + {{- if ne .Name ""}} \ + '--{{ .Name }}[{{ .Description }}]' + {{- end }} + {{- if ne .ShortName ""}} \ '-{{ .ShortName }}[{{ .Description }}]' + {{- end }} {{- end }} {{- if gt (len .Cmd.Subcommands) 0 -}} {{ " " }}\ @@ -64,6 +67,18 @@ var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(` function _{{ $varName }} { {{ template "cmd" (map "Cmd" .RootCmd) -}} + + {{- if gt (len .GlobalOpts) 0 }} + _arguments + {{- range .GlobalOpts -}} + {{- if ne .Name ""}} \ + '--{{ .Name }}[{{ .Description }}]' + {{- end }} + {{- if ne .ShortName ""}} \ + '-{{ .ShortName }}[{{ .Description }}]' + {{- end }} + {{- end }} + {{- end }} } compdef _{{ $varName }} {{ $progName }}