Skip to content

Commit

Permalink
feat(config): Respect XDG_CONFIG_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 23, 2024
1 parent 2f9a692 commit c8efc0c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions internal/config/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ func InitViper() error {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
home, err := os.UserHomeDir()
if err != nil {
return err
var configDir string
if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" {
configDir = filepath.Join(xdgConfigHome, "nightscout-menu-bar")
} else {
home, err := os.UserHomeDir()
if err != nil {
return err
}
configDir = filepath.Join(home, ".config", "nightscout-menu-bar")
}
configDir := filepath.Join(home, ".config", "nightscout-menu-bar")

viper.SetConfigName("config")
viper.SetConfigType("yaml")
Expand Down

0 comments on commit c8efc0c

Please sign in to comment.