Skip to content

Commit e7cdd3c

Browse files
authored
Merge pull request #350 from NamedIdentity/fix/xdg-base-directory-paths
Fix XDG base directory support for config and log paths
2 parents 9f3903f + 29191fe commit e7cdd3c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,9 @@ const defaultConfig: PluginConfig = {
526526
},
527527
}
528528

529-
const GLOBAL_CONFIG_DIR = join(homedir(), ".config", "opencode")
529+
const GLOBAL_CONFIG_DIR = process.env.XDG_CONFIG_HOME
530+
? join(process.env.XDG_CONFIG_HOME, "opencode")
531+
: join(homedir(), ".config", "opencode")
530532
const GLOBAL_CONFIG_PATH_JSONC = join(GLOBAL_CONFIG_DIR, "dcp.jsonc")
531533
const GLOBAL_CONFIG_PATH_JSON = join(GLOBAL_CONFIG_DIR, "dcp.json")
532534

lib/logger.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export class Logger {
99

1010
constructor(enabled: boolean) {
1111
this.enabled = enabled
12-
const opencodeConfigDir = join(homedir(), ".config", "opencode")
13-
this.logDir = join(opencodeConfigDir, "logs", "dcp")
12+
const dataHome =
13+
process.env.XDG_DATA_HOME || join(homedir(), ".local", "share")
14+
this.logDir = join(dataHome, "opencode", "logs", "dcp")
1415
}
1516

1617
private async ensureLogDir() {

lib/state/persistence.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ export interface PersistedSessionState {
2525
lastUpdated: string
2626
}
2727

28-
const STORAGE_DIR = join(homedir(), ".local", "share", "opencode", "storage", "plugin", "dcp")
28+
const STORAGE_DIR = join(
29+
process.env.XDG_DATA_HOME || join(homedir(), ".local", "share"),
30+
"opencode",
31+
"storage",
32+
"plugin",
33+
"dcp",
34+
)
2935

3036
async function ensureStorageDir(): Promise<void> {
3137
if (!existsSync(STORAGE_DIR)) {

0 commit comments

Comments
 (0)