From 9832e3299d56e3a86999f67c9e70cb34b88eaec2 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 16 Oct 2023 09:23:31 +0800 Subject: [PATCH] feature: add xdg base support (#2913) --- constant/path.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/constant/path.go b/constant/path.go index d7477e0e..0d82f549 100644 --- a/constant/path.go +++ b/constant/path.go @@ -18,6 +18,9 @@ var ( ) // Path is used to get the configuration path +// +// on Unix systems, `$HOME/.config/clash`. +// on Windows, `%USERPROFILE%/.config/clash`. var Path = func() *path { homeDir, err := os.UserHomeDir() if err != nil { @@ -25,6 +28,13 @@ var Path = func() *path { } allowUnsafePath, _ := strconv.ParseBool(os.Getenv("SKIP_SAFE_PATH_CHECK")) 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} }()