feat(path): support for XDG base directories (#95)

closes #93
This commit is contained in:
VERSE
2026-07-31 22:58:09 +07:00
committed by GitHub
parent aba4dc9716
commit bf75dc239b
2 changed files with 19 additions and 2 deletions
+16
View File
@@ -6,6 +6,10 @@ import (
) )
func ConfigPath() (string, error) { func ConfigPath() (string, error) {
configHome := os.Getenv("XDG_CONFIG_HOME")
if configHome != "" {
return filepath.Join(configHome, "iris", "config.toml"), nil
}
dir, err := os.UserConfigDir() dir, err := os.UserConfigDir()
if err != nil { if err != nil {
return "", err return "", err
@@ -25,7 +29,19 @@ func StatePath() (string, error) {
return filepath.Join(dataHome, "iris", "state.toml"), nil 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) { func CachePath() (string, error) {
cacheHome := os.Getenv("XDG_CACHE_HOME")
if cacheHome != "" {
return filepath.Join(cacheHome, "iris"), nil
}
dir, err := os.UserCacheDir() dir, err := os.UserCacheDir()
if err != nil { if err != nil {
return "", err return "", err
+3 -2
View File
@@ -11,6 +11,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/versenilvis/iris/internal/config"
_ "modernc.org/sqlite" _ "modernc.org/sqlite"
) )
@@ -37,11 +38,11 @@ type FrecencyStore struct {
func NewFrecencyStore(dbPath string) (*FrecencyStore, error) { func NewFrecencyStore(dbPath string) (*FrecencyStore, error) {
if dbPath == "" { if dbPath == "" {
home, err := os.UserHomeDir() var err error
dbPath, err = config.HistoryDBPath()
if err != nil { if err != nil {
return nil, err return nil, err
} }
dbPath = filepath.Join(home, ".local", "share", "iris", "history.db")
} }
dir := filepath.Dir(dbPath) dir := filepath.Dir(dbPath)