From 5819e04c537d729afc66fb61e529f546c06e094a Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 16 Aug 2018 19:17:38 +1000 Subject: use shibukawa/configdir package to follow xdg spec config directory structure --- pkg/config/app_config.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'pkg') diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 68c065e33..f34848123 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -3,10 +3,9 @@ package config import ( "bytes" "log" - "os" "os/user" - "path/filepath" + "github.com/shibukawa/configdir" "github.com/spf13/viper" ) @@ -89,15 +88,20 @@ func LoadUserConfig() (*viper.Viper, error) { return nil, err } v.SetConfigName("config") - configPath := homeDirectory() + "/lazygit/" - if _, err := os.Stat(filepath.FromSlash(configPath + "config.yaml")); !os.IsNotExist(err) { - v.AddConfigPath(configPath) - err = v.MergeInConfig() + + // chucking my name there is not for vanity purposes, the xdg spec (and that + // function) requires a vendor name. May as well line up with github + configDirs := configdir.New("jesseduffield", "lazygit") + folder := configDirs.QueryFolderContainsFile("config.yml") + if folder != nil { + configData, err := folder.ReadFile("config.yml") if err != nil { return nil, err } + if err = v.MergeConfig(bytes.NewReader(configData)); err != nil { + return nil, err + } } - return v, nil } -- cgit v1.2.3