create-plugin
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Plugin
创建插件
Build an oh-my-claude statusline plugin — from idea to working output in one pass.
构建oh-my-claude状态行插件——从构思到可用产出一步完成。
Workflow
工作流程
-
Clarify the plugin's purpose — ask what it should display, when to hide, and any config the user wants. See PATTERNS.md for data fields and common patterns.
-
Choose plugin type — JS plugin (default, in-process, fast) or script plugin (any language, runs as subprocess). Use JS unless the user specifies a language or the task needs external tools. See PATTERNS.md.
-
Scaffold the plugin — run(or
omc create <name>). This creates the directory structure atomc create <name> --script --lang=python|bash.~/.claude/oh-my-claude/plugins/<name>/ -
Implement render logic — edit the generated(or
plugin.jsscript). Follow the contract in PATTERNS.md. Always use optional chaining. Always return null when data is missing.plugin -
Set default config — add any configurable values to(JS) or
meta.defaultConfig(script). Use concrete defaults, not empty strings.plugin.json -
Test the plugin — run. Verify it returns
omc test <name>with mock data and returns{ text, style }with empty data.null -
Wire it up — run(with
omc add <name>and--line Nif needed). Run--leftto verify placement.omc show -
Verify end-to-end — runto confirm no errors. Run
omc doctorto see the live preview.omc show
-
明确插件用途 —— 询问插件需要展示的内容、隐藏时机,以及用户需要的任何配置项。数据字段和通用模式请参考PATTERNS.md。
-
选择插件类型 —— JS插件(默认,进程内运行,速度快)或脚本插件(支持任意语言,作为子进程运行)。除非用户指定了语言或任务需要用到外部工具,否则优先使用JS。参考PATTERNS.md。
-
生成插件骨架 —— 运行(或
omc create <name>)。该命令会在omc create <name> --script --lang=python|bash路径下创建目录结构。~/.claude/oh-my-claude/plugins/<name>/ -
实现渲染逻辑 —— 编辑生成的(或
plugin.js脚本)。遵循PATTERNS.md中定义的规范。始终使用可选链语法。数据缺失时始终返回null。plugin -
设置默认配置 —— 将所有可配置项添加到(JS插件)或
meta.defaultConfig(脚本插件)中。使用具体的默认值,不要用空字符串。plugin.json -
测试插件 —— 运行。验证插件在使用模拟数据时返回
omc test <name>,数据为空时返回{ text, style }。null -
接入状态行 —— 运行(如有需要可搭配
omc add <name>和--line N参数)。运行--left验证插件位置是否正确。omc show -
端到端验证 —— 运行确认没有错误。运行
omc doctor查看实时预览效果。omc show
Self-review checklist
自检清单
Before delivering, verify ALL:
- matches the directory name
meta.name - is a single clear sentence
meta.description - uses optional chaining for every data access (
render())data?.field?.subfield - returns
render()when required data is missing (never crashes)null - succeeds — shows text with mock data, returns null with empty data
omc test <name> - reports no errors for this plugin
omc doctor - Shell commands (if any) use from
cachedExec, never rawsrc/cache.jsexecSync - Config keys have sensible defaults in (no empty strings or nulls for required values)
defaultConfig - Plugin text is short — fits in a statusline segment (under ~30 chars typical)
- confirms the plugin appears where the user wants it
omc show
交付前请确认所有项都已满足:
- 与目录名一致
meta.name - 是清晰的单句描述
meta.description - 中所有数据访问都使用可选链语法(
render())data?.field?.subfield - 所需数据缺失时返回
render()(永远不会崩溃)null - 运行成功——使用模拟数据时返回文本,数据为空时返回null
omc test <name> - 未报告该插件存在任何错误
omc doctor - 如有Shell命令,使用提供的
src/cache.js,绝不使用原生cachedExecexecSync - 配置项在中有合理的默认值(必填项不要使用空字符串或null)
defaultConfig - 插件文本简短——适合放在状态行分段中(通常不超过30个字符)
- 确认插件显示在用户期望的位置
omc show
Golden rules
黄金准则
Hard rules. Never violate these.
- Never crash the statusline. Every data access uses optional chaining. Every render returns or
{ text, style }. No exceptions, no throws. A plugin that crashes breaks the entire statusbar for the user.null - Null means hide. Return when data is unavailable. Never return empty strings, placeholder text, or fallback values that clutter the bar.
null - Cache all shell commands. Use from
cachedExec(key, command, ttlMs). Rawsrc/cache.jsin render blocks the entire statusline pipeline.execSync - Test before wiring. Always run before
omc test <name>. A broken plugin silently disappears — testing catches errors the statusline would swallow.omc add <name> - Keep text short. Statusline segments share a single terminal line. Aim for under 30 characters. Use abbreviations, symbols, and rounding (e.g. not
42%,42.53%not$2.41).$2.4100 - Config has real defaults. Every key in must have a usable value. Users override config — they don't fill in required blanks.
defaultConfig - Match name to directory. must exactly match the plugin directory name. Mismatches cause the plugin to silently not load.
meta.name
硬性规则,绝对不能违反。
- 绝对不能导致状态行崩溃。 所有数据访问都使用可选链语法。所有渲染结果要么返回,要么返回
{ text, style }。没有例外,不要抛出异常。崩溃的插件会导致用户的整个状态栏无法使用。null - Null代表隐藏。 数据不可用时返回。不要返回空字符串、占位文本,或者其他会让状态栏变得杂乱的回退值。
null - 所有Shell命令都要缓存。 使用提供的
src/cache.js。渲染逻辑中的原生cachedExec(key, command, ttlMs)会阻塞整个状态行处理流程。execSync - 接入前先测试。 运行之前务必先运行
omc add <name>。损坏的插件会静默消失,测试可以捕获状态行可能忽略的错误。omc test <name> - 保持文本简短。 状态行分段共享同一终端行。尽量控制在30个字符以内。使用缩写、符号和舍入处理(例如用而不是
42%,用42.53%而不是$2.41)。$2.4100 - 配置要有真实默认值。 中的每个键都必须有可用值。用户是覆盖配置,而不是填写必填空项。
defaultConfig - 名称与目录匹配。 必须与插件目录名完全一致。不匹配会导致插件静默加载失败。
meta.name
Reference files
参考文件
| File | Contents |
|---|---|
| PATTERNS.md | Data fields, plugin templates, cachedExec usage, script plugin format, style tokens, common patterns |
| 文件 | 内容 |
|---|---|
| PATTERNS.md | 数据字段、插件模板、cachedExec用法、脚本插件格式、样式标记、通用模式 |