diff --git a/cmd.go b/cmd.go index 2da1f9b5..1e9e0b58 100644 --- a/cmd.go +++ b/cmd.go @@ -132,6 +132,8 @@ func handleCmd() (err error) { config.saveConfig() } + config.expandEnv() + if cmdArgs.existsArg("h", "help") { err = handleHelp() return @@ -196,7 +198,8 @@ func handlePrint() (err error) { switch { case cmdArgs.existsArg("d", "defaultconfig"): var tmpConfig Configuration - defaultSettings(&tmpConfig) + tmpConfig.defaultSettings() + tmpConfig.expandEnv() fmt.Printf("%v", tmpConfig) case cmdArgs.existsArg("g", "currentconfig"): fmt.Printf("%v", config) diff --git a/config.go b/config.go index e4c2ecaa..e2dc47dc 100644 --- a/config.go +++ b/config.go @@ -146,9 +146,14 @@ func (config *Configuration) saveConfig() error { return err } -func defaultSettings(config *Configuration) { +func (config *Configuration) defaultSettings() { + buildDir := "$HOME/.config/yay" + if os.Getenv("XDG_CONFIG_HOME") != "" { + buildDir = "$XDG_CONFIG_HOME/yay" + } + config.AURURL = "https://aur.archlinux.org" - config.BuildDir = cacheHome + config.BuildDir = buildDir config.CleanAfter = false config.Editor = "" config.EditorFlags = "" @@ -188,6 +193,32 @@ func defaultSettings(config *Configuration) { config.CombinedUpgrade = false } + +func (config *Configuration) expandEnv() { + config.AURURL = os.ExpandEnv(config.AURURL) + config.BuildDir = os.ExpandEnv(config.BuildDir) + config.Editor = os.ExpandEnv(config.Editor) + config.EditorFlags = os.ExpandEnv(config.EditorFlags) + config.MakepkgBin = os.ExpandEnv(config.MakepkgBin) + config.MakepkgConf = os.ExpandEnv(config.MakepkgConf) + config.PacmanBin = os.ExpandEnv(config.PacmanBin) + config.PacmanConf = os.ExpandEnv(config.PacmanConf) + config.GpgFlags = os.ExpandEnv(config.GpgFlags) + config.MFlags = os.ExpandEnv(config.MFlags) + config.GitFlags = os.ExpandEnv(config.GitFlags) + config.SortBy = os.ExpandEnv(config.SortBy) + config.TarBin = os.ExpandEnv(config.TarBin) + config.GitBin = os.ExpandEnv(config.GitBin) + config.GpgBin = os.ExpandEnv(config.GpgBin) + config.ReDownload = os.ExpandEnv(config.ReDownload) + config.ReBuild = os.ExpandEnv(config.ReBuild) + config.AnswerClean = os.ExpandEnv(config.AnswerClean) + config.AnswerDiff = os.ExpandEnv(config.AnswerDiff) + config.AnswerEdit = os.ExpandEnv(config.AnswerEdit) + config.AnswerUpgrade = os.ExpandEnv(config.AnswerUpgrade) + config.RemoveMake = os.ExpandEnv(config.RemoveMake) +} + // Editor returns the preferred system editor. func editor() (string, []string) { switch { diff --git a/main.go b/main.go index 53a6db58..b108bf9b 100644 --- a/main.go +++ b/main.go @@ -198,7 +198,7 @@ func main() { } exitOnError(setPaths()) - defaultSettings(&config) + config.defaultSettings() exitOnError(initHomeDirs()) exitOnError(initConfig()) exitOnError(cmdArgs.parseCommandLine())