Skip to content

Commit 213c39b

Browse files
author
OhMyOpenCode Toggle Tool
committed
Release v1.0.2: Cross-platform support with global commands
## Major Changes ### Cross-Platform Support - Added macOS/Linux installation and uninstallation scripts - Updated tool to automatically detect platform (Windows/macOS/Linux) - Platform-independent configuration path detection - All script files are executable on Unix-like systems ### Global Command Support - Windows: Automatic PATH configuration for global 'omo' command - macOS/Linux: Symbolic link creation in /usr/local/bin - Commands can be used from any directory after installation ### Project Structure Refactoring - Created src/ directory for source code - Created scripts/ directory for all installation/uninstallation scripts - Clean separation of concerns - Removed redundant wrapper scripts from root directory ### Other Improvements - Removed config.example.json (tool auto-detects config file) - Updated CI workflow to use new project structure - Improved regex-based plugin status detection - Enhanced error messages and user feedback ## Files Added - scripts/install.sh - macOS/Linux installer - scripts/uninstall.sh - macOS/Linux uninstaller - scripts/omo.sh - macOS/Linux wrapper - AGENTS.md - Development guidelines ## Files Removed - config.example.json - No longer needed - Root-level *.bat/*.sh shortcuts - Redundant ## Testing - Verified on Windows with Node.js v24.13.0 - All commands tested: on, off, enable, disable, status - Configuration file modification verified
1 parent fccd095 commit 213c39b

File tree

17 files changed

+700
-167
lines changed

17 files changed

+700
-167
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,25 @@ jobs:
2424

2525
- name: Test toggle script
2626
run: |
27-
# Create test config
28-
cp config.example.json opencode.json
29-
27+
# Create test config directory and file
28+
mkdir -p ~/.config/opencode
29+
cat > ~/.config/opencode/opencode.json << 'EOF'
30+
{
31+
"$schema": "https://opencode.ai/config.json",
32+
"plugin": [
33+
"oh-my-opencode"
34+
]
35+
}
36+
EOF
37+
3038
# Test status
31-
node omo-toggle/omo-toggle.js status
32-
39+
node src/omo-toggle.js status
40+
3341
# Test disable
34-
node omo-toggle/omo-toggle.js off
35-
42+
node src/omo-toggle.js off
43+
3644
# Test enable
37-
node omo-toggle/omo-toggle.js on
38-
45+
node src/omo-toggle.js on
46+
3947
# Verify config changes
40-
cat opencode.json
48+
cat ~/.config/opencode/opencode.json

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ coverage/
5252
# dotenv environment variables file
5353
.env
5454

55-
# Local config files (keep example configs)
55+
# Local config files
5656
config.json
57-
!config.example.json
5857

5958
# OpenCode specific (keep private)
6059
oh-my-opencode.json

AGENTS.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# AGENTS.md - OhMyOpenCode Toggle Tool
2+
3+
This repository contains a simple Node.js tool for toggling OhMyOpenCode plugin status.
4+
5+
## Build/Test Commands
6+
7+
**Note:** This project has no build step. It's a pure Node.js script.
8+
9+
### Running Tests
10+
Tests are manual integration checks via CI. Run locally:
11+
12+
```bash
13+
# Setup test config
14+
cp config.example.json opencode.json
15+
16+
# Test all commands
17+
node omo-toggle/omo-toggle.js status
18+
node omo-toggle/omo-toggle.js off
19+
node omo-toggle/omo-toggle.js on
20+
21+
# Or use the convenience script (after installation)
22+
cd %USERPROFILE%\.config\opencode
23+
omo status
24+
omo off
25+
omo on
26+
```
27+
28+
**Test via CI:**
29+
```bash
30+
# GitHub Actions workflow (automated)
31+
./.github/workflows/ci.yml
32+
# Tests on Node.js 16.x, 18.x, 20.x
33+
```
34+
35+
### Running the Tool
36+
```bash
37+
# Direct execution
38+
node omo-toggle/omo-toggle.js [command]
39+
40+
# After installation
41+
odo [command]
42+
opo [command]
43+
44+
# Valid commands: on, off, enable, disable, status
45+
```
46+
47+
## Code Style Guidelines
48+
49+
### JavaScript/Node.js
50+
51+
**Language:** CommonJS (not ESM modules)
52+
53+
**Imports:**
54+
- Use `require()` for built-in modules only
55+
- No external dependencies
56+
- Import order: built-ins first (fs, path, etc.)
57+
58+
```javascript
59+
// ✅ Correct
60+
const fs = require('fs');
61+
const path = require('path');
62+
```
63+
64+
**Indentation:**
65+
- 4 spaces (no tabs)
66+
67+
**Naming Conventions:**
68+
- Variables: camelCase (`configText`, `configPath`)
69+
- Files: kebab-case (`omo-toggle.js`)
70+
71+
**Error Handling:**
72+
- Use try-catch blocks for file operations
73+
- Console.error for error messages
74+
- `process.exit(1)` on fatal errors
75+
76+
```javascript
77+
try {
78+
configText = fs.readFileSync(configPath, 'utf8');
79+
} catch (error) {
80+
console.error('无法读取配置文件:', error.message);
81+
process.exit(1);
82+
}
83+
```
84+
85+
**Comments & Messages:**
86+
- Use Chinese for user-facing messages
87+
- Use English for inline code comments (mixed codebase)
88+
- Include emoji for status messages: ✅ ❌
89+
90+
```javascript
91+
// 获取命令行参数
92+
const command = process.argv[2];
93+
94+
console.log('✅ OhMyOpenCode 已启用');
95+
console.error('无法读取配置文件:', error.message);
96+
```
97+
98+
### Code Organization
99+
100+
**Project Structure:**
101+
- `/omo-toggle/` - Core tool directory
102+
- `omo-toggle.js` - Main logic
103+
- `omo.bat` - Windows batch wrapper
104+
- `/` - Root directory
105+
- `omo.bat` - Installation shortcut
106+
- `install.bat` - Windows installer
107+
- `config.example.json` - Config template
108+
- `README.md` - Chinese documentation
109+
110+
**Script Entry Point:**
111+
- Shebang: `#!/usr/bin/env node`
112+
- CLI args: `process.argv[2]` for commands
113+
- Exit codes: 0 for success, 1 for errors
114+
115+
### Files & Configurations
116+
117+
**Target Config File:** `opencode.json` (not in repo)
118+
- Location: Parent directory of script
119+
- Modified in-place for enable/disable toggling
120+
121+
**No Build Tools:**
122+
- No package.json
123+
- No dependencies
124+
- No TypeScript
125+
- No linting config
126+
127+
### Windows Batch Scripts
128+
129+
**Style:**
130+
- Use `@echo off` (silent execution)
131+
- SET variables for paths
132+
- XCOPY for directory copy
133+
- COPY for file copy
134+
- `>nul` to suppress copy output
135+
- Error handling with `errorlevel`
136+
137+
```batch
138+
@echo off
139+
setlocal enabledelayedexpansion
140+
set TARGET_DIR=%USERPROFILE%\.config\opencode
141+
```
142+
143+
## Development Notes
144+
145+
**Core Logic:**
146+
- Plugin enabled when `"oh-my-opencode"` appears in config
147+
- Plugin disabled when `"oh-my-opencode"` appears commented (`//` prefix)
148+
- Simple string replacement: removes/adds `//` prefix
149+
- Status check: searches for unquoted plugin string
150+
151+
**Critical Paths:**
152+
- Config path: `path.join(__dirname, '..', 'opencode.json')`
153+
- This assumes the script runs from `omo-toggle/` subdirectory
154+
155+
**Platform Support:**
156+
- Primary: Windows (batch scripts)
157+
- Cross-platform: Node.js script runs anywhere
158+
159+
**No Testing Framework:**
160+
- Manual testing only
161+
- CI runs direct Node.js commands (no test harness)

README.md

Lines changed: 81 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,93 @@
1-
# GitHub 发布说明
1+
# OhMyOpenCode Toggle Tool
22

3-
## Release v1.0.0 说明
4-
5-
### 🎉 首次发布
6-
7-
OhMyOpenCode Toggle Tool 是一个简单的命令行工具,用于在 OhMyOpenCode 插件的启用和禁用状态之间切换。
3+
一个简单的命令行工具,用于在 OhMyOpenCode 插件的启用和禁用状态之间切换。
84

95
### ✨ 特性
106

117
- 🔄 简单的命令行开关(`omo on/off/status`
128
- ⚡ 即时状态检查
139
- 🗂️ 清晰的目录结构
14-
- 💻 跨平台支持(Windows 批处理 + Node.js)
15-
- 📦 自动安装脚本
10+
- 💻 跨平台支持(Windows/macOS/Linux)
11+
- 🌐 全局命令支持(任意目录可用)
12+
- 📦 自动化安装脚本
1613

1714
### 🚀 安装方法
1815

19-
#### 方法1: 手动安装
20-
1. 下载项目文件
21-
2. 运行 `install.bat`
22-
3. 在 OpenCode 配置目录中使用 `omo` 命令
16+
#### Windows
17+
```bash
18+
# 双击运行或在命令行中执行
19+
scripts\install.bat
20+
```
21+
22+
#### macOS/Linux
23+
```bash
24+
# 给脚本添加执行权限
25+
chmod +x scripts/install.sh
26+
27+
# 运行安装脚本
28+
./scripts/install.sh
29+
```
2330

24-
#### 方法2: 直接复制
25-
1.`omo-toggle/` 目录复制到你的 OpenCode 配置目录
26-
2.`omo.bat` 复制到配置目录根目录
27-
3. 使用命令行工具
31+
如果提示需要管理员权限:
32+
```bash
33+
sudo ./scripts/install.sh
34+
```
2835

2936
### 📖 使用说明
3037

38+
安装完成后,无论在哪个目录都可以使用 `omo` 命令:
39+
3140
```bash
3241
# 查看当前状态
3342
omo status
3443

3544
# 启用 OhMyOpenCode
3645
omo on
46+
# 或者
47+
omo enable
3748

3849
# 禁用 OhMyOpenCode
3950
omo off
51+
# 或者
52+
omo disable
53+
```
54+
55+
### ⚙️ 工作原理
56+
57+
工具通过修改 `~/.config/opencode/opencode.json` 文件来切换插件状态:
58+
59+
- **启用**: ` "oh-my-opencode"`
60+
- **禁用**: ` //"oh-my-opencode"`
61+
62+
修改后需要重启 OpenCode 才能使更改生效。
63+
64+
工具会自动检测 OpenCode 配置文件,无需手动创建。
65+
66+
### 🔧 高级用法
67+
68+
#### 自定义配置路径
69+
如果 OpenCode 配置路径不在默认位置,可以设置环境变量:
70+
71+
```bash
72+
# Windows
73+
set OPENCODE_CONFIG_PATH=C:\custom\path\to\config
74+
75+
# macOS/Linux
76+
export OPENCODE_CONFIG_PATH=/custom/path/to/config
77+
```
78+
79+
#### 直接使用 Node.js
80+
```bash
81+
# 进入 src 目录后
82+
cd ~/.config/opencode/src
83+
node omo-toggle.js [command]
4084
```
4185

42-
### ⚠️ 注意事项
86+
### ⚠️ 系统要求
4387

44-
- 需要重启 OpenCode 才能使更改生效
45-
- 需要安装 Node.js
46-
- 需要有修改配置文件的权限
88+
- Node.js(已安装)
89+
- 修改配置文件的权限
90+
- OpenCode 已正确安装
4791

4892
### 🤝 贡献
4993

@@ -57,13 +101,20 @@ omo off
57101
oh-my-opencode-toggle/
58102
├── README.md # 项目说明
59103
├── LICENSE # MIT 许可证
60-
├── .gitignore # Git 忽略文件
61-
├── package.json # Node.js 包配置
62-
├── config.example.json # 示例配置文件
63-
├── install.bat # Windows 安装脚本
64-
├── omo.bat # 根目录快捷方式
65-
└── omo-toggle/ # 工具目录
66-
├── omo-toggle.js # Node.js 核心脚本
67-
├── omo.bat # 本地批处理脚本
68-
└── README.md # 工具详细说明
69-
```
104+
├── AGENTS.md # 代码规范
105+
├── .gitignore # Git 忽略文件
106+
├── src/ # 源代码目录
107+
│ └── omo-toggle.js # Node.js 核心脚本
108+
└── scripts/ # 脚本目录
109+
├── install.bat # Windows 安装脚本
110+
├── install.sh # macOS/Linux 安装脚本
111+
├── uninstall.bat # Windows 卸载脚本
112+
├── uninstall.sh # macOS/Linux 卸载脚本
113+
├── omo.bat # Windows 命令包装器
114+
├── omo.sh # macOS/Linux 命令包装器
115+
└── README.md # 脚本详细说明
116+
```
117+
118+
## License
119+
120+
MIT License

config.example.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)