refactor(config): cache config directory

This commit is contained in:
ayn2op 2026-07-20 21:19:10 -04:00
parent e32e07805f
commit aa27aea627

View file

@ -6,6 +6,7 @@ import (
"log/slog"
"os"
"path/filepath"
"sync"
"unicode/utf8"
"github.com/BurntSushi/toml"
@ -135,14 +136,17 @@ type (
//go:embed config.toml
var defaultCfg []byte
func DefaultPath() string {
var dir = sync.OnceValue(func() string {
path, err := os.UserConfigDir()
if err != nil {
slog.Info("user config dir cannot be determined; falling back to the current dir", "err", err)
path = "."
}
return filepath.Join(path, consts.Name)
})
return filepath.Join(path, consts.Name, fileName)
func DefaultPath() string {
return filepath.Join(dir(), fileName)
}
// Load reads the configuration file and parses it.