Skip to content

Commit 60cf9c2

Browse files
committed
fix: use XDG_CONFIG_HOME for session and config files
Move default session index from proton/sessions.db (relative to CWD) to $XDG_CONFIG_HOME/proton-cli/sessions.db (defaults to ~/.config/proton-cli/sessions.db). Same for config.yaml. Add cmd/xdg.go with xdgConfigPath helper that respects XDG_CONFIG_HOME and falls back to ~/.config/.
1 parent ffe6d77 commit 60cf9c2

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

cmd/rootCmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ var (
5959
}
6060

6161
if rootParams.ConfigFile == "" {
62-
rootParams.ConfigFile = "proton/config.yaml"
62+
rootParams.ConfigFile = xdgConfigPath("config.yaml")
6363
}
6464

6565
if rootParams.SessionFile == "" {
66-
rootParams.SessionFile = "proton/sessions.db"
66+
rootParams.SessionFile = xdgConfigPath("sessions.db")
6767
}
6868

6969
Timeout = rootParams.Timeout

cmd/xdg.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cli
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
7+
8+
const appName = "proton-cli"
9+
10+
// xdgConfigPath returns a path under $XDG_CONFIG_HOME/proton-cli/.
11+
// Defaults to ~/.config/proton-cli/ if XDG_CONFIG_HOME is unset.
12+
func xdgConfigPath(name string) string {
13+
base := os.Getenv("XDG_CONFIG_HOME")
14+
if base == "" {
15+
home, err := os.UserHomeDir()
16+
if err != nil {
17+
// Last resort: use current directory.
18+
return filepath.Join(appName, name)
19+
}
20+
base = filepath.Join(home, ".config")
21+
}
22+
return filepath.Join(base, appName, name)
23+
}

0 commit comments

Comments
 (0)