diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-16 19:17:38 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-16 19:17:38 +1000 |
commit | 5819e04c537d729afc66fb61e529f546c06e094a (patch) | |
tree | 937327ec7add8657fc63b9360495f071c675413c | |
parent | fd3ce215763f227c9ab7b4e03c9b2a391ab45719 (diff) |
use shibukawa/configdir package to follow xdg spec config directory structure
-rw-r--r-- | pkg/config/app_config.go | 18 |
1 files changed, 11 insertions, 7 deletions
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 } |