diff --git a/src/templates/completion-zsh.handlebars b/src/templates/completion-zsh.handlebars new file mode 100644 index 0000000..27f9a9f --- /dev/null +++ b/src/templates/completion-zsh.handlebars @@ -0,0 +1,39 @@ +#compdef _{{spec.name}} {{spec.name}} +# Zsh completion for {{spec.name}} +# Auto-generated by cli-spec-generator + +_{{_name}}() { + local line + + _arguments -C \ + '(-h --help)'{-h,--help}'[Show help]' \ + '(-v --version)'{-v,--version}'[Show version]' \ + {{#each spec.globalOptions}} + '{{#if short}}-{{short}}, {{/if}}--{{name}}[{{escape description}}]' \ + {{/each}} + {{#each spec.commands}} + '{{name}}[{{escape description}}]' \ + {{/each}} + '*::arg:->args' + + if [[ -z "$line" ]]; then + return + fi + + local cmd="${line[1]}" + shift line + + case "$cmd" in + {{#each spec.commands}} + {{name}}) + _arguments \ + {{#each options}} + '{{#if short}}-{{short}}, {{/if}}--{{name}}[{{escape description}}]' \ + {{/each}} + '*::arg:->args' + ;; + {{/each}} + esac +} + +_{{_spec.name}} "$@"