Handle XDG_CONFIG_DIRS in Go as well
This commit is contained in:
parent
a84b688038
commit
0614c63966
@ -71,33 +71,44 @@ var KittyExe = (&Once[string]{Run: func() string {
|
|||||||
}}).Get
|
}}).Get
|
||||||
|
|
||||||
var ConfigDir = (&Once[string]{Run: func() (config_dir string) {
|
var ConfigDir = (&Once[string]{Run: func() (config_dir string) {
|
||||||
if os.Getenv("KITTY_CONFIG_DIRECTORY") != "" {
|
if kcd := os.Getenv("KITTY_CONFIG_DIRECTORY"); kcd != "" {
|
||||||
config_dir = Abspath(Expanduser(os.Getenv("KITTY_CONFIG_DIRECTORY")))
|
return Abspath(Expanduser(kcd))
|
||||||
} else {
|
}
|
||||||
var locations []string
|
var locations []string
|
||||||
if os.Getenv("XDG_CONFIG_HOME") != "" {
|
seen := Set[string]{}
|
||||||
locations = append(locations, os.Getenv("XDG_CACHE_HOME"))
|
add := func(x string) {
|
||||||
|
x = Abspath(Expanduser(x))
|
||||||
|
if !seen.Has(x) {
|
||||||
|
seen.Add(x)
|
||||||
|
locations = append(locations, x)
|
||||||
}
|
}
|
||||||
locations = append(locations, Expanduser("~/.config"))
|
}
|
||||||
if runtime.GOOS == "darwin" {
|
if xh := os.Getenv("XDG_CONFIG_HOME"); xh != "" {
|
||||||
locations = append(locations, Expanduser("~/Library/Preferences"))
|
add(xh)
|
||||||
|
}
|
||||||
|
if dirs := os.Getenv("XDG_CONFIG_DIRS"); dirs != "" {
|
||||||
|
for _, candidate := range strings.Split(dirs, ":") {
|
||||||
|
add(candidate)
|
||||||
}
|
}
|
||||||
for _, loc := range locations {
|
}
|
||||||
if loc != "" {
|
add("~/.config")
|
||||||
q := filepath.Join(loc, "kitty")
|
if runtime.GOOS == "darwin" {
|
||||||
if _, err := os.Stat(filepath.Join(q, "kitty.conf")); err == nil {
|
add("~/Library/Preferences")
|
||||||
config_dir = q
|
}
|
||||||
break
|
for _, loc := range locations {
|
||||||
}
|
if loc != "" {
|
||||||
}
|
q := filepath.Join(loc, "kitty")
|
||||||
}
|
if _, err := os.Stat(filepath.Join(q, "kitty.conf")); err == nil {
|
||||||
for _, loc := range locations {
|
config_dir = q
|
||||||
if loc != "" {
|
return
|
||||||
config_dir = filepath.Join(loc, "kitty")
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
config_dir = os.Getenv("XDG_CONFIG_HOME")
|
||||||
|
if config_dir == "" {
|
||||||
|
config_dir = "~/.config"
|
||||||
|
}
|
||||||
|
config_dir = filepath.Join(Expanduser(config_dir), "kitty")
|
||||||
return
|
return
|
||||||
}}).Get
|
}}).Get
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user