Skip to content

Commit

Permalink
Feature: add xdg base support (#2913)
Browse files Browse the repository at this point in the history
  • Loading branch information
septs authored Aug 28, 2023
1 parent 4a91932 commit 927c0db
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions constant/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ import (
const Name = "clash"

// 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 {
homeDir, _ = os.Getwd()
}

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"}
}()

Expand Down

0 comments on commit 927c0db

Please sign in to comment.