Skip to content

Commit 97988b9

Browse files
authored
Merge pull request #119 from yassun7010/fix_zsh_completion
Fix zsh completion
2 parents f0d20b3 + 053d0a0 commit 97988b9

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

cmdcomp/v2/completion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def generate_v2(shell: ShellType, config: V2Config) -> str:
1414
loader=FileSystemLoader(Path(__file__).parent / "templates"),
1515
)
1616
env.filters["ident"] = lambda x: re.sub(r"[\*\.,-]", "_", str(x))
17+
env.filters["escape"] = lambda x: x.replace("'", "''")
1718
template = env.get_template(f"{shell.value}.sh.jinja")
1819

1920
return template.render(

cmdcomp/v2/templates/zsh.sh.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{%- endif -%}
2828
{%- endmacro -%}
2929

30-
#!/bin/zsh
30+
#compdef {{ app_name }}
3131
#
3232
# Code generated by cmdcomp "{{ version }}". DO NOT EDIT.
3333
# For more information about cmdcomp, please refer to https://github.com/yassun7010/cmdcomp .
@@ -54,7 +54,7 @@
5454
local -a _{{ scope|ident }}_subcmds
5555
_{{ scope|ident }}_subcmds=(
5656
{%- for subcmd_name, subcommand in command.subcommands.items() %}
57-
{{ candidate(subcmd_name, subcommand) }}'{{ description(subcommand) }}'
57+
{{ candidate(subcmd_name, subcommand) }}'{{ description(subcommand)|escape }}'
5858
{%- endfor %}
5959
)
6060
{% endif %}
@@ -65,7 +65,7 @@
6565
{%- endfor %}
6666
_arguments -C \
6767
{%- for kwd_name, keyword in command.keyword_arguments.items() %}
68-
{{ candidate(kwd_name, keyword) }}'{{ description(keyword) }}{{ contents(kwd_name, keyword) }}' \
68+
{{ candidate(kwd_name, keyword) }}'{{ description(keyword)|escape }}{{ contents(kwd_name, keyword) }}' \
6969
{%- endfor %}
7070
{%- for pos_name, positional in command.positional_arguments.items() %}
7171
'{{ pos_name }}{{ contents(pos_name, positional) }}' \

examples/demo/output.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/zsh
1+
#compdef mycli
22
#
33
# Code generated by cmdcomp "$CMDCOMP_VERSION". DO NOT EDIT.
44
# For more information about cmdcomp, please refer to https://github.com/yassun7010/cmdcomp .

examples/v2/output.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/zsh
1+
#compdef cliname
22
#
33
# Code generated by cmdcomp "$CMDCOMP_VERSION". DO NOT EDIT.
44
# For more information about cmdcomp, please refer to https://github.com/yassun7010/cmdcomp .

0 commit comments

Comments
 (0)