Feature: add xdg base support (#2913)

This commit is contained in:
septs 2023-08-28 22:47:56 +08:00 committed by GitHub
parent 4a91932554
commit 927c0db3a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -10,6 +10,9 @@ import (
const Name = "clash" const Name = "clash"
// Path is used to get the configuration path // Path is used to get the configuration path
//
// on Unix systems, `$HOME/.config/clash`.
// on Windows, `%USERPROFILE%/.config/clash`.
var Path = func() *path { var Path = func() *path {
homeDir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
@ -17,6 +20,12 @@ var Path = func() *path {
} }
homeDir = P.Join(homeDir, ".config", Name) homeDir = P.Join(homeDir, ".config", Name)
if _, err = os.Stat(homeDir); err != nil {
if configHome, ok := os.LookupEnv("XDG_CONFIG_HOME"); ok {
homeDir = P.Join(configHome, Name)
}
}
return &path{homeDir: homeDir, configFile: "config.yaml"} return &path{homeDir: homeDir, configFile: "config.yaml"}
}() }()