From 6e72173cdec04766efcaaccccf7029fba8ce2e1a Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 20 Dec 2025 13:10:35 +0900 Subject: [PATCH] fix(config): support both ~/.config and %APPDATA% paths on Windows (#131) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- README.ja.md | 2 +- README.ko.md | 2 +- README.md | 2 +- src/shared/config-path.ts | 23 ++++++++++++++++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.ja.md b/README.ja.md index 9e56555..bd64ddf 100644 --- a/README.ja.md +++ b/README.ja.md @@ -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` | ใ‚นใ‚ญใƒผใƒž่‡ชๅ‹•่ฃœๅฎŒใŒใ‚ตใƒใƒผใƒˆใ•ใ‚Œใฆใ„ใพใ™๏ผš diff --git a/README.ko.md b/README.ko.md index 87a71a7..9fd732b 100644 --- a/README.ko.md +++ b/README.ko.md @@ -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 ์ž๋™ ์™„์„ฑ์ด ์ง€์›๋ฉ๋‹ˆ๋‹ค: diff --git a/README.md b/README.md index 7ffb693..55b1111 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/shared/config-path.ts b/src/shared/config-path.ts index 05606cb..7c12a4b 100644 --- a/src/shared/config-path.ts +++ b/src/shared/config-path.ts @@ -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") }