Files
iris-context/internal/config/paths.go
T
VERSE d299d1c7c7 refactor(path): use XDG config for all platforms (#119)
closes #112
Replace `os.UserConfigDir()` with explicit `~/.config` fallback to align
macOS, Linux, and other platforms on same config location
Respects `XDG_CONFIG_HOME` if set, otherwise uses `~/.config/iris/`
2026-08-04 23:51:59 +07:00

71 lines
1.5 KiB
Go

package config
import (
"os"
"path/filepath"
)
func ConfigPath() (string, error) {
configHome := os.Getenv("XDG_CONFIG_HOME")
if configHome != "" {
return filepath.Join(configHome, "iris", "config.toml"), nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".config", "iris", "config.toml"), nil
}
func ThemePath() (string, error) {
configHome := os.Getenv("XDG_CONFIG_HOME")
if configHome != "" {
return filepath.Join(configHome, "iris", "theme.toml"), nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".config", "iris", "theme.toml"), nil
}
func StatePath() (string, error) {
dataHome := os.Getenv("XDG_DATA_HOME")
if dataHome == "" {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
dataHome = filepath.Join(home, ".local", "share")
}
return filepath.Join(dataHome, "iris", "state.toml"), nil
}
func HistoryDBPath() (string, error) {
statePath, err := StatePath()
if err != nil {
return "", err
}
return filepath.Join(filepath.Dir(statePath), "history.db"), nil
}
func CachePath() (string, error) {
cacheHome := os.Getenv("XDG_CACHE_HOME")
if cacheHome != "" {
return filepath.Join(cacheHome, "iris"), nil
}
dir, err := os.UserCacheDir()
if err != nil {
return "", err
}
return filepath.Join(dir, "iris"), nil
}
func CrashDir() (string, error) {
cache, err := CachePath()
if err != nil {
return "", err
}
return filepath.Join(cache, "crashes"), nil
}