Skip to content

Commit

Permalink
Use: indent.
Browse files Browse the repository at this point in the history
  • Loading branch information
yassun7010 committed Aug 2, 2023
1 parent 8a8aee6 commit 572e762
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cmdcomp/v2/completion.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from pathlib import Path
from typing import Any

Expand All @@ -12,6 +13,7 @@ def generate_v2(shell: ShellType, config: V2Config) -> str:
env = Environment(
loader=FileSystemLoader(Path(__file__).parent / "templates"),
)
env.filters["ident"] = lambda x: re.sub(r"[,.-]", "_", x)
template = env.get_template(f"{shell.value}.sh.jinja")

return template.render(
Expand Down
6 changes: 3 additions & 3 deletions cmdcomp/v2/templates/bash.sh.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set func_name = "_" + app_name|replace("-","_") -%}
{%- set func_name = "_" + app_name|ident -%}
{%- set scope = "" -%}

{#- macro def -#}
Expand Down Expand Up @@ -117,7 +117,7 @@ cur=$COMP_CWORD
cur=$(( cur + opts_cur + 1 ))
;;
{% for (tag, command_name), subcommand in append_key_tag(commands[app_name].subcommands, func_name).items() recursive %}
{%- set new_tag = tag + "_" + command_name|replace("-","_") %}
{%- set new_tag = tag + "_" + command_name|ident %}
{{ tag }},{{ command_name }}
{%- for alias in subcommand.aliases -%}
|{{ tag }},{{ alias }}
Expand All @@ -140,7 +140,7 @@ cur=$COMP_CWORD
return 0
;;
{% for (tag, command_name), subcommand in append_key_tag(commands[app_name].subcommands, func_name).items() recursive %}
{%- set new_tag = tag + "_" + command_name|replace("-","_") %}
{%- set new_tag = tag + "_" + command_name|ident %}
{{ new_tag }})
{{ command_completion(subcommand, loop.depth + 1)|indent(6) }}

Expand Down
8 changes: 4 additions & 4 deletions cmdcomp/v2/templates/zsh.sh.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set func_name = "_" + app_name|replace("-","_") -%}
{%- set func_name = "_" + app_name|ident -%}
{%- set scope = "" -%}

{#- macro def -#}
Expand Down Expand Up @@ -44,8 +44,8 @@
{%- set scope = scope + "_" + cmd_name %}
{{ ([cmd_name] + command.aliases)|join("|") }})
{%- if command.has_subcommands %}
local -a _{{ scope|replace("-", "_") }}_subcmds
_{{ scope|replace("-", "_") }}_subcmds=(
local -a _{{ scope|ident }}_subcmds
_{{ scope|ident }}_subcmds=(
{%- for subcmd_name, subcommand in command.subcommands.items() %}
{{ candidate(subcmd_name, subcommand) }}'{{ description(subcommand) }}'
{%- endfor %}
Expand All @@ -61,7 +61,7 @@
{%- if command.has_positional_wildcard_argument %}
'*{{ contents("*", command.positional_wildcard_argument) }}' \
{%- elif command.has_subcommands %}
'1: :_values "subcommand" ${_{{ scope|replace("-", "_") }}_subcmds[@]}' \
'1: :_values "subcommand" ${_{{ scope|ident }}_subcmds[@]}' \
'*:: :->args' \
{%- endif %}
&& ret=0
Expand Down

0 comments on commit 572e762

Please sign in to comment.