package utils import ( "os" "path/filepath" "strings" ) func ExpandPath(path string) (string, error) { expanded := os.ExpandEnv(path) expanded = filepath.Clean(expanded) if strings.HasPrefix(expanded, "~") { home, err := os.UserHomeDir() if err != nil { return "", err } expanded = filepath.Join(home, expanded[1:]) } return expanded, nil } func XDGConfigHome() string { if configHome := os.Getenv("XDG_CONFIG_HOME"); configHome != "" { return configHome } if home, err := os.UserHomeDir(); err == nil { return filepath.Join(home, ".config") } return filepath.Join(os.TempDir(), ".config") } func XDGCacheHome() string { if cacheHome := os.Getenv("XDG_CACHE_HOME"); cacheHome != "" { return cacheHome } if home, err := os.UserHomeDir(); err == nil { return filepath.Join(home, ".cache") } return filepath.Join(os.TempDir(), ".cache") } func XDGDataHome() string { if dataHome := os.Getenv("XDG_DATA_HOME"); dataHome != "" { return dataHome } if home, err := os.UserHomeDir(); err == nil { return filepath.Join(home, ".local", "share") } return filepath.Join(os.TempDir(), ".local", "share") }