Skip to content

Commit 131c917

Browse files
committed
fix(config): support both ~/.config and %APPDATA% paths on Windows
Implements dual-path config resolution on Windows to ensure backward compatibility while maintaining cross-platform consistency. Checks ~/.config first (new standard), falls back to %APPDATA% for existing installations. Resolves #129 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
1 parent f5ce55e commit 131c917

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

README.ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ Oh My OpenCode は以下の場所からフックを読み込んで実行しま
643643

644644
| プラットフォーム | ユーザー設定パス |
645645
|------------------|------------------|
646-
| **Windows** | `%APPDATA%\opencode\oh-my-opencode.json` |
646+
| **Windows** | `~/.config/opencode/oh-my-opencode.json` (優先) または `%APPDATA%\opencode\oh-my-opencode.json` (フォールバック) |
647647
| **macOS/Linux** | `~/.config/opencode/oh-my-opencode.json` |
648648

649649
スキーマ自動補完がサポートされています:

README.ko.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ Oh My OpenCode는 다음 위치의 훅을 읽고 실행합니다:
637637

638638
| 플랫폼 | 사용자 설정 경로 |
639639
|--------|------------------|
640-
| **Windows** | `%APPDATA%\opencode\oh-my-opencode.json` |
640+
| **Windows** | `~/.config/opencode/oh-my-opencode.json` (우선) 또는 `%APPDATA%\opencode\oh-my-opencode.json` (fallback) |
641641
| **macOS/Linux** | `~/.config/opencode/oh-my-opencode.json` |
642642

643643
Schema 자동 완성이 지원됩니다:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ Config file locations (priority order):
703703

704704
| Platform | User Config Path |
705705
|----------|------------------|
706-
| **Windows** | `%APPDATA%\opencode\oh-my-opencode.json` |
706+
| **Windows** | `~/.config/opencode/oh-my-opencode.json` (preferred) or `%APPDATA%\opencode\oh-my-opencode.json` (fallback) |
707707
| **macOS/Linux** | `~/.config/opencode/oh-my-opencode.json` |
708708

709709
Schema autocomplete supported:

src/shared/config-path.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
import * as path from "path"
22
import * as os from "os"
3+
import * as fs from "fs"
34

45
/**
56
* Returns the user-level config directory based on the OS.
67
* - Linux/macOS: XDG_CONFIG_HOME or ~/.config
7-
* - Windows: %APPDATA%
8+
* - Windows: Checks ~/.config first (cross-platform), then %APPDATA% (fallback)
9+
*
10+
* On Windows, prioritizes ~/.config for cross-platform consistency.
11+
* Falls back to %APPDATA% for backward compatibility with existing installations.
812
*/
913
export function getUserConfigDir(): string {
1014
if (process.platform === "win32") {
11-
return process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming")
15+
const crossPlatformDir = path.join(os.homedir(), ".config")
16+
const crossPlatformConfigPath = path.join(crossPlatformDir, "opencode", "oh-my-opencode.json")
17+
18+
const appdataDir = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming")
19+
const appdataConfigPath = path.join(appdataDir, "opencode", "oh-my-opencode.json")
20+
21+
if (fs.existsSync(crossPlatformConfigPath)) {
22+
return crossPlatformDir
23+
}
24+
25+
if (fs.existsSync(appdataConfigPath)) {
26+
return appdataDir
27+
}
28+
29+
return crossPlatformDir
1230
}
1331

14-
// Linux, macOS, and other Unix-like systems: respect XDG_CONFIG_HOME
1532
return process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config")
1633
}
1734

0 commit comments

Comments
 (0)