diff --git a/internal/config/paths.go b/internal/config/paths.go index 52a2d86..b5752c4 100644 --- a/internal/config/paths.go +++ b/internal/config/paths.go @@ -11,6 +11,12 @@ import ( // system func Paths(sys string, envvars map[string]string) ([]string, error) { + // get the user's home directory + home, err := homedir.Dir() + if err != nil { + return []string{}, fmt.Errorf("failed to get user home directory: %v", err) + } + // if `CHEAT_CONFIG_PATH` is set, expand ~ and return it if confpath, ok := envvars["CHEAT_CONFIG_PATH"]; ok { @@ -32,10 +38,10 @@ func Paths(sys string, envvars map[string]string) ([]string, error) { paths = append(paths, path.Join(xdgpath, "/cheat/conf.yml")) } - // `HOME` will always be set on a POSIX-compliant system, though + // if `XDG_CONFIG_HOME` is not set, search the user's home directory paths = append(paths, []string{ - path.Join(envvars["HOME"], ".config/cheat/conf.yml"), - path.Join(envvars["HOME"], ".cheat/conf.yml"), + path.Join(home, ".config/cheat/conf.yml"), + path.Join(home, ".cheat/conf.yml"), }...) return paths, nil