feature: add xdg base support (#2913)
This commit is contained in:
parent
98df77439c
commit
d2499cd69d
@ -18,6 +18,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 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 {
|
||||||
@ -25,6 +28,13 @@ var Path = func() *path {
|
|||||||
}
|
}
|
||||||
allowUnsafePath, _ := strconv.ParseBool(os.Getenv("SKIP_SAFE_PATH_CHECK"))
|
allowUnsafePath, _ := strconv.ParseBool(os.Getenv("SKIP_SAFE_PATH_CHECK"))
|
||||||
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", allowUnsafePath: allowUnsafePath}
|
return &path{homeDir: homeDir, configFile: "config.yaml", allowUnsafePath: allowUnsafePath}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user