Skip to content

Commit

Permalink
Merge pull request #119 from yassun7010/fix_zsh_completion
Browse files Browse the repository at this point in the history
Fix zsh completion
  • Loading branch information
yassun7010 authored Nov 14, 2023
2 parents f0d20b3 + 053d0a0 commit 97988b9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmdcomp/v2/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions cmdcomp/v2/templates/zsh.sh.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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 %}
Expand All @@ -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) }}' \
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/output.zsh
Original file line number Diff line number Diff line change
@@ -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 .
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/output.zsh
Original file line number Diff line number Diff line change
@@ -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 .
Expand Down

0 comments on commit 97988b9

Please sign in to comment.