Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zsh completion #119

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading