mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
fix: XDG_CONFIG_HOME mishandling
Attempts to resolve an issue regarding automatic config file generation, as referenced in #501. This issue is believed occur when `XDG_CONFIG_HOME` is unset.
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
// system
|
||||
func Paths(sys string, envvars map[string]string) ([]string, error) {
|
||||
|
||||
// if CHEAT_CONFIG_PATH is set, expand ~ and return it
|
||||
// if `CHEAT_CONFIG_PATH` is set, expand ~ and return it
|
||||
if confpath, ok := envvars["CHEAT_CONFIG_PATH"]; ok {
|
||||
|
||||
// expand ~
|
||||
@@ -25,11 +25,20 @@ func Paths(sys string, envvars map[string]string) ([]string, error) {
|
||||
|
||||
switch sys {
|
||||
case "darwin", "linux", "freebsd":
|
||||
return []string{
|
||||
path.Join(envvars["XDG_CONFIG_HOME"], "/cheat/conf.yml"),
|
||||
paths := []string{}
|
||||
|
||||
// don't include the `XDG_CONFIG_HOME` path if that envvar is not set
|
||||
if xdgpath, ok := envvars["XDG_CONFIG_HOME"]; ok {
|
||||
paths = append(paths, path.Join(xdgpath, "/cheat/conf.yml"))
|
||||
}
|
||||
|
||||
// `HOME` will always be set on a POSIX-compliant system, though
|
||||
paths = append(paths, []string{
|
||||
path.Join(envvars["HOME"], ".config/cheat/conf.yml"),
|
||||
path.Join(envvars["HOME"], ".cheat/conf.yml"),
|
||||
}, nil
|
||||
}...)
|
||||
|
||||
return paths, nil
|
||||
case "windows":
|
||||
return []string{
|
||||
path.Join(envvars["APPDATA"], "/cheat/conf.yml"),
|
||||
|
||||
Reference in New Issue
Block a user