fix(config): support both ~/.config and %APPDATA% paths on Windows (#131)

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)
This commit is contained in:
YeonGyu-Kim
2025-12-20 13:10:35 +09:00
committed by GitHub
parent a926ebcf8c
commit 6e72173cde
4 changed files with 23 additions and 6 deletions

View File

@@ -643,7 +643,7 @@ Oh My OpenCode は以下の場所からフックを読み込んで実行しま
| プラットフォーム | ユーザー設定パス |
|------------------|------------------|
| **Windows** | `%APPDATA%\opencode\oh-my-opencode.json` |
| **Windows** | `~/.config/opencode/oh-my-opencode.json` (優先) または `%APPDATA%\opencode\oh-my-opencode.json` (フォールバック) |
| **macOS/Linux** | `~/.config/opencode/oh-my-opencode.json` |
スキーマ自動補完がサポートされています:

View File

@@ -637,7 +637,7 @@ Oh My OpenCode는 다음 위치의 훅을 읽고 실행합니다:
| 플랫폼 | 사용자 설정 경로 |
|--------|------------------|
| **Windows** | `%APPDATA%\opencode\oh-my-opencode.json` |
| **Windows** | `~/.config/opencode/oh-my-opencode.json` (우선) 또는 `%APPDATA%\opencode\oh-my-opencode.json` (fallback) |
| **macOS/Linux** | `~/.config/opencode/oh-my-opencode.json` |
Schema 자동 완성이 지원됩니다:

View File

@@ -703,7 +703,7 @@ Config file locations (priority order):
| Platform | User Config Path |
|----------|------------------|
| **Windows** | `%APPDATA%\opencode\oh-my-opencode.json` |
| **Windows** | `~/.config/opencode/oh-my-opencode.json` (preferred) or `%APPDATA%\opencode\oh-my-opencode.json` (fallback) |
| **macOS/Linux** | `~/.config/opencode/oh-my-opencode.json` |
Schema autocomplete supported:

View File

@@ -1,17 +1,34 @@
import * as path from "path"
import * as os from "os"
import * as fs from "fs"
/**
* Returns the user-level config directory based on the OS.
* - Linux/macOS: XDG_CONFIG_HOME or ~/.config
* - Windows: %APPDATA%
* - Windows: Checks ~/.config first (cross-platform), then %APPDATA% (fallback)
*
* On Windows, prioritizes ~/.config for cross-platform consistency.
* Falls back to %APPDATA% for backward compatibility with existing installations.
*/
export function getUserConfigDir(): string {
if (process.platform === "win32") {
return process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming")
const crossPlatformDir = path.join(os.homedir(), ".config")
const crossPlatformConfigPath = path.join(crossPlatformDir, "opencode", "oh-my-opencode.json")
const appdataDir = process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming")
const appdataConfigPath = path.join(appdataDir, "opencode", "oh-my-opencode.json")
if (fs.existsSync(crossPlatformConfigPath)) {
return crossPlatformDir
}
if (fs.existsSync(appdataConfigPath)) {
return appdataDir
}
return crossPlatformDir
}
// Linux, macOS, and other Unix-like systems: respect XDG_CONFIG_HOME
return process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config")
}