@@ -1,6 +1,7 @@
11package config
22
33import (
4+ "cmp"
45 "context"
56 "encoding/json"
67 "fmt"
@@ -695,19 +696,22 @@ func hasAWSCredentials(env env.Env) bool {
695696
696697// GlobalConfig returns the global configuration file path for the application.
697698func GlobalConfig() string {
698− xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
699− if xdgConfigHome != "" {
699+ if crushGlobal := os.Getenv("CRUSH_GLOBAL_CONFIG"); crushGlobal != "" {
700+ return filepath.Join(crushGlobal, fmt.Sprintf("%s.json", appName))
701+ }
702+ if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" {
700703 return filepath.Join(xdgConfigHome, appName, fmt.Sprintf("%s.json", appName))
701704 }
702−
703705 return filepath.Join(home.Dir(), ".config", appName, fmt.Sprintf("%s.json", appName))
704706}
705707
706708// GlobalConfigData returns the path to the main data directory for the application.
707709// this config is used when the app overrides configurations instead of updating the global config.
708710func GlobalConfigData() string {
709− xdgDataHome := os.Getenv("XDG_DATA_HOME")
710− if xdgDataHome != "" {
711+ if crushData := os.Getenv("CRUSH_GLOBAL_DATA"); crushData != "" {
712+ return filepath.Join(crushData, fmt.Sprintf("%s.json", appName))
713+ }
714+ if xdgDataHome := os.Getenv("XDG_DATA_HOME"); xdgDataHome != "" {
711715 return filepath.Join(xdgDataHome, appName, fmt.Sprintf("%s.json", appName))
712716 }
713717
@@ -715,10 +719,10 @@ func GlobalConfigData() string {
715719 // for windows, it should be in `%LOCALAPPDATA%/crush/`
716720 // for linux and macOS, it should be in `$HOME/.local/share/crush/`
717721 if runtime.GOOS == "windows" {
718− localAppData := os.Getenv("LOCALAPPDATA")
719− if localAppData == "" {
720− localAppData = filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Local")
721− }
722+ localAppData := cmp.Or(
723+ os.Getenv("LOCALAPPDATA"),
724+ filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Local"),
725+ )
722726 return filepath.Join(localAppData, appName, fmt.Sprintf("%s.json", appName))
723727 }
724728