-
Notifications
You must be signed in to change notification settings - Fork 2
/
completion.jinja
55 lines (51 loc) · 1.25 KB
/
completion.jinja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#compdef {{ tool.name }}
# ----------------------------------------------------------------------------------------
# Zsh completion file for {{ tool.name }}
#
{% if tool.description %}
{% for line in tool.description.splitlines() %}
# {{ line }}
{% endfor %}
{% endif %}
#
# This file was generated with help from Zargparse (https://github.com/ctil/zargparse)
# ----------------------------------------------------------------------------------------
typeset -A opt_args
_{{ tool.name }}() {
{% if tool.subcommands %}
# Define the subcommands
local -a commands
commands=(
{% for cmd in tool.subcommands %}
'{{ cmd.name }}:{{ cmd.help_text }}'
{% endfor %}
)
{% endif %}
# Global flags (i.e. ones not associated with a subcommand)
_arguments \
{% if tool.subcommands %}
"1: :{_describe 'command' commands}" \
{% endif %}
{% for flag in tool.flags %}
{{ flag.arg_string }} \
{% endfor %}
'*:: :->args'
{% if tool.subcommands %}
# Flags for each subcommand
case $state in
args)
case $words[1] in
{% for cmd in tool.subcommands %}
{{ cmd.name }})
_arguments \
{% for flag in cmd.flags %}
{{ flag.arg_string }} \
{% endfor %}
;;
{% endfor %}
esac
;;
esac
{% endif %}
}
_{{ tool.name }}