Skip to content

Commit 572e762

Browse files
committed
Use: indent.
1 parent 8a8aee6 commit 572e762

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

cmdcomp/v2/completion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from pathlib import Path
23
from typing import Any
34

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

1719
return template.render(

cmdcomp/v2/templates/bash.sh.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{%- set func_name = "_" + app_name|replace("-","_") -%}
1+
{%- set func_name = "_" + app_name|ident -%}
22
{%- set scope = "" -%}
33

44
{#- macro def -#}
@@ -117,7 +117,7 @@ cur=$COMP_CWORD
117117
cur=$(( cur + opts_cur + 1 ))
118118
;;
119119
{% for (tag, command_name), subcommand in append_key_tag(commands[app_name].subcommands, func_name).items() recursive %}
120-
{%- set new_tag = tag + "_" + command_name|replace("-","_") %}
120+
{%- set new_tag = tag + "_" + command_name|ident %}
121121
{{ tag }},{{ command_name }}
122122
{%- for alias in subcommand.aliases -%}
123123
|{{ tag }},{{ alias }}
@@ -140,7 +140,7 @@ cur=$COMP_CWORD
140140
return 0
141141
;;
142142
{% for (tag, command_name), subcommand in append_key_tag(commands[app_name].subcommands, func_name).items() recursive %}
143-
{%- set new_tag = tag + "_" + command_name|replace("-","_") %}
143+
{%- set new_tag = tag + "_" + command_name|ident %}
144144
{{ new_tag }})
145145
{{ command_completion(subcommand, loop.depth + 1)|indent(6) }}
146146

cmdcomp/v2/templates/zsh.sh.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{%- set func_name = "_" + app_name|replace("-","_") -%}
1+
{%- set func_name = "_" + app_name|ident -%}
22
{%- set scope = "" -%}
33

44
{#- macro def -#}
@@ -44,8 +44,8 @@
4444
{%- set scope = scope + "_" + cmd_name %}
4545
{{ ([cmd_name] + command.aliases)|join("|") }})
4646
{%- if command.has_subcommands %}
47-
local -a _{{ scope|replace("-", "_") }}_subcmds
48-
_{{ scope|replace("-", "_") }}_subcmds=(
47+
local -a _{{ scope|ident }}_subcmds
48+
_{{ scope|ident }}_subcmds=(
4949
{%- for subcmd_name, subcommand in command.subcommands.items() %}
5050
{{ candidate(subcmd_name, subcommand) }}'{{ description(subcommand) }}'
5151
{%- endfor %}
@@ -61,7 +61,7 @@
6161
{%- if command.has_positional_wildcard_argument %}
6262
'*{{ contents("*", command.positional_wildcard_argument) }}' \
6363
{%- elif command.has_subcommands %}
64-
'1: :_values "subcommand" ${_{{ scope|replace("-", "_") }}_subcmds[@]}' \
64+
'1: :_values "subcommand" ${_{{ scope|ident }}_subcmds[@]}' \
6565
'*:: :->args' \
6666
{%- endif %}
6767
&& ret=0

0 commit comments

Comments
 (0)