lov-zsh-alias

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

终端快捷指令 · Shell Shortcuts

终端快捷指令 · Shell 快捷指令

Append a zsh alias or function to
~/.zshrc
behind sentinel markers, so re-running updates the entry in place instead of duplicating it. Works for both English (
zxsd
) and 中文 (
中信书店
) trigger names.
在
~/.zshrc
的 sentinel 标记范围内追加 zsh alias 或 function, 因此重复运行时会原地更新该条目,而不是创建重复项。英文(
zxsd
)和中文 (
中信书店
)触发名称均可使用。

When to Use

何时使用

  • User wants to bind a trigger word to a shell command ("我输入 X 就跑 Y")
  • User wants a 中文 trigger ("输入'中信书店'就启动 claude 说一句开心话")
  • User wants multiple aliases pointing to the same command
  • User wants to remove a previously-added alias
Do NOT use for:
  • System-level shortcuts that need to fire without pressing Enter — that's an input-method or Hammerspoon job, not a shell alias. Tell the user.
  • Non-zsh shells unless they explicitly pass
    --rcfile
    .
  • 用户希望将触发词绑定到 shell 命令(“我输入 X 就跑 Y”)
  • 用户希望使用中文触发词(“输入'中信书店'就启动 claude 说一句开心话”)
  • 用户希望创建多个指向同一命令的 alias
  • 用户希望移除之前添加的 alias
不适用于:
  • 无需按 Enter 即可触发的系统级快捷键——这属于输入法或 Hammerspoon 的范畴, 而不是 shell alias。请告知用户。
  • 非 zsh shell,除非用户明确传入
    --rcfile
    。

Workflow (MANDATORY)

工作流(必须执行)

Step 1: Ask the user (only what's missing)

步骤 1:向用户询问(仅询问缺失信息)

Use
AskUserQuestion
to collect anything not already obvious from context. Typical fields:
  • Trigger name(s): the word(s) the user types. Multiple OK.
  • Command: the shell command to run. Quote carefully.
  • Style:
    • function
      (default) — supports CJK names, supports passing args via
      "$@"
    • simple alias
      — only for ASCII names; uses
      alias name='cmd'
      form
If the user already gave the trigger + command in plain language ("中信书店 → 启动 claude 说一句开心话"), skip the question and proceed.
使用
AskUserQuestion
收集上下文中尚不明确的信息。 常见字段:
  • 触发名称:用户输入的词语。可以提供多个。
  • 命令:要运行的 shell 命令。注意正确引用。
  • 样式:
    • function
      (默认)——支持 CJK 名称,支持通过
      "$@"
      传递参数
    • simple alias
      ——仅适用于 ASCII 名称;使用
      alias name='cmd'
      形式
如果用户已经用自然语言提供了触发词和命令(“中信书店 → 启动 claude 说一句开心话”),则跳过提问并继续执行。

Step 2: Dry-run preview

步骤 2:试运行预览

bash
python3 scripts/add_alias.py \
  --name <trigger> \
  --cmd '<shell command>' \
  --comment '<one-line explanation>' \
  [--also-as <other-trigger>] \
  --dry-run
Show the rendered block to the user.
bash
python3 scripts/add_alias.py \
  --name <trigger> \
  --cmd '<shell command>' \
  --comment '<one-line explanation>' \
  [--also-as <other-trigger>] \
  --dry-run
向用户展示渲染后的代码块。

Step 3: Apply

步骤 3:应用

Re-run without
--dry-run
. The script writes a sentinel-wrapped block to
~/.zshrc
. Re-running with the same
--name
updates in place.
重新运行同一命令,但去掉
--dry-run
。脚本会将带 sentinel 标记的代码块写入
~/.zshrc
。使用相同的
--name
重新运行时会原地更新条目。

Step 4: Tell the user to reload

步骤 4:告知用户重新加载

bash
source ~/.zshrc
Then they can type the trigger + Enter.
bash
source ~/.zshrc
随后用户可以输入触发词并按 Enter。

Removing an alias

移除 alias

bash
python3 scripts/add_alias.py \
  --name <trigger> --cmd unused --remove
bash
python3 scripts/add_alias.py \
  --name <trigger> --cmd unused --remove

CLI Reference

CLI 参考

ArgumentDefaultDescription
--name
(required)Trigger word; ASCII or 中文
--cmd
(required)Shell command to run
--also-as
noneExtra alias name(s); repeatable
--comment
emptyComment line above the block
--simple
offUse
alias=
form (ASCII names only)
--rcfile
~/.zshrc
Target rc file
--dry-run
offPrint, don't write
--remove
offRemove the entry for
--name
参数默认值说明
--name
(必填)触发词;支持 ASCII 或中文
--cmd
(必填)要运行的 shell 命令
--also-as
无额外的 alias 名称;可重复使用
--comment
空代码块上方的注释行
--simple
关闭使用
alias=
形式(仅限 ASCII 名称)
--rcfile
~/.zshrc
目标 rc 文件
--dry-run
关闭仅打印,不写入
--remove
关闭移除
--name
对应的条目

Block Format

代码块格式

Each entry is wrapped in sentinel markers so the script can find and update it on re-run:
undefined
每个条目都由 sentinel 标记包裹,因此脚本可以在重复运行时查找并更新它:
undefined

>>> lov-zsh-alias >>> <name>

>>> lov-zsh-alias >>> <name>

<comment>

<comment>

<name>() { <cmd> } <also-as>() { <name> "$@" }
<name>() { <cmd> } <also-as>() { <name> "$@" }

<<< lov-zsh-alias <<< <name>

<<< lov-zsh-alias <<< <name>

undefined
undefined

Notes for Claude

Claude 注意事项

  • zsh supports CJK function names natively — no quoting trickery needed.
  • shell aliases ALWAYS require pressing Enter. If the user expects "auto fire on typing", clarify upfront — they need an input method shortcut or Hammerspoon, not this skill.
  • Don't
    --simple
    for CJK names; the script will reject it.
  • The user must
    source ~/.zshrc
    (or open a new terminal) to pick up the new alias. Always say so after writing.
  • zsh 原生支持 CJK function 名称,无需使用引号规避技巧。
  • shell alias 始终需要按 Enter。如果用户期望“输入时自动触发”,应提前说明—— 他们需要输入法快捷键或 Hammerspoon,而不是此 skill。
  • CJK 名称不要使用
    --simple
    ;脚本会拒绝该操作。
  • 用户必须执行
    source ~/.zshrc
    (或打开新终端)才能加载新 alias。 写入后务必告知用户。

User Configuration

用户配置

Set
SKILL_ZSH_ALIAS_RCFILE
to change the default rc file.
--rcfile
still takes precedence.
设置
SKILL_ZSH_ALIAS_RCFILE
可更改默认 rc 文件。
--rcfile
仍具有更高优先级。

Runtime context (shared)

运行时上下文(共享)

运行前读取本 Skill 包的
skill.yaml
,由宿主提供
skill-runtime/v1
上下文。字段解析顺序为:当前请求、项目上下文、个人 Preferences、品牌 Profile、通用默认值。
  • 只使用 Manifest 声明的字段;Profile 保存公开品牌事实,Preferences 保存个人工作偏好。
  • required: true
    字段缺失时,按 Manifest 的问题配置向用户提出一个聚焦问题;用户明确同意后再保存回答。
  • 报错提供可复制的
    context_id
    、字段路径与来源,诊断内容避开秘密、完整私人路径和原始配置。
运行前读取本 Skill 包的
skill.yaml
,由宿主提供
skill-runtime/v1
上下文。字段解析顺序为:当前请求、项目上下文、个人 Preferences、品牌 Profile、通用默认值。
  • 只使用 Manifest 声明的字段;Profile 保存公开品牌事实,Preferences 保存个人工作偏好。
  • required: true
    字段缺失时,按 Manifest 的问题配置向用户提出一个聚焦问题;用户明确同意后再保存回答。
  • 报错提供可复制的
    context_id
    、字段路径与来源,诊断内容避开秘密、完整私人路径和原始配置。