From e2e03e2d462f8361f87b155317a1c6972bdd87bc Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Tue, 14 Nov 2023 21:32:47 +0900 Subject: [PATCH 1/2] fix: template. --- cmdcomp/v2/templates/zsh.sh.jinja | 2 +- examples/demo/output.zsh | 2 +- examples/v2/output.zsh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmdcomp/v2/templates/zsh.sh.jinja b/cmdcomp/v2/templates/zsh.sh.jinja index e762922..da8704d 100644 --- a/cmdcomp/v2/templates/zsh.sh.jinja +++ b/cmdcomp/v2/templates/zsh.sh.jinja @@ -27,7 +27,7 @@ {%- endif -%} {%- endmacro -%} -#!/bin/zsh +#compdef {{ app_name }} # # Code generated by cmdcomp "{{ version }}". DO NOT EDIT. # For more information about cmdcomp, please refer to https://github.com/yassun7010/cmdcomp . diff --git a/examples/demo/output.zsh b/examples/demo/output.zsh index 3982105..174bdf0 100644 --- a/examples/demo/output.zsh +++ b/examples/demo/output.zsh @@ -1,4 +1,4 @@ -#!/bin/zsh +#compdef mycli # # Code generated by cmdcomp "$CMDCOMP_VERSION". DO NOT EDIT. # For more information about cmdcomp, please refer to https://github.com/yassun7010/cmdcomp . diff --git a/examples/v2/output.zsh b/examples/v2/output.zsh index 0cdf26e..b6bcb69 100644 --- a/examples/v2/output.zsh +++ b/examples/v2/output.zsh @@ -1,4 +1,4 @@ -#!/bin/zsh +#compdef cliname # # Code generated by cmdcomp "$CMDCOMP_VERSION". DO NOT EDIT. # For more information about cmdcomp, please refer to https://github.com/yassun7010/cmdcomp . From 053d0a019ead74bfbb4344c073e49868a877f932 Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Tue, 14 Nov 2023 21:35:49 +0900 Subject: [PATCH 2/2] fix: escape. --- cmdcomp/v2/completion.py | 1 + cmdcomp/v2/templates/zsh.sh.jinja | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmdcomp/v2/completion.py b/cmdcomp/v2/completion.py index 6c34445..c68fd35 100644 --- a/cmdcomp/v2/completion.py +++ b/cmdcomp/v2/completion.py @@ -14,6 +14,7 @@ def generate_v2(shell: ShellType, config: V2Config) -> str: loader=FileSystemLoader(Path(__file__).parent / "templates"), ) env.filters["ident"] = lambda x: re.sub(r"[\*\.,-]", "_", str(x)) + env.filters["escape"] = lambda x: x.replace("'", "''") template = env.get_template(f"{shell.value}.sh.jinja") return template.render( diff --git a/cmdcomp/v2/templates/zsh.sh.jinja b/cmdcomp/v2/templates/zsh.sh.jinja index da8704d..a4f891d 100644 --- a/cmdcomp/v2/templates/zsh.sh.jinja +++ b/cmdcomp/v2/templates/zsh.sh.jinja @@ -54,7 +54,7 @@ local -a _{{ scope|ident }}_subcmds _{{ scope|ident }}_subcmds=( {%- for subcmd_name, subcommand in command.subcommands.items() %} - {{ candidate(subcmd_name, subcommand) }}'{{ description(subcommand) }}' + {{ candidate(subcmd_name, subcommand) }}'{{ description(subcommand)|escape }}' {%- endfor %} ) {% endif %} @@ -65,7 +65,7 @@ {%- endfor %} _arguments -C \ {%- for kwd_name, keyword in command.keyword_arguments.items() %} - {{ candidate(kwd_name, keyword) }}'{{ description(keyword) }}{{ contents(kwd_name, keyword) }}' \ + {{ candidate(kwd_name, keyword) }}'{{ description(keyword)|escape }}{{ contents(kwd_name, keyword) }}' \ {%- endfor %} {%- for pos_name, positional in command.positional_arguments.items() %} '{{ pos_name }}{{ contents(pos_name, positional) }}' \