BREAKING CHANGE: default darwin system config filenames
to `XDG_CONFIG_HOME` or `~/.config`. Only if both of them
are absent, fallback to `os.UserConfigDir()` return value
(`~/Library/Application Support`).
As a side-effect, render true `man` page clause
> On startup hut will look for a file at
> $XDG_CONFIG_HOME/hut/config
but do not enforce the following
> If unset, $XDG_CONFIG_HOME defaults to ~/.config/*
i.e., do not create `~/.config` if there isn't one.
(In case the maintainer has different ideas about this.)
Rationale:
To anyone who uses `XDG_CONFIG_HOME` or `~/.config`
it should generally be unexpected to find that these
locations aren't used and, instead, non-standard
`~/Library/Application Support` is used instead.
(It could be expected if the application were installed
by way of a GUI installer and used GUI, not text, as its
main road to configuration.)
---
config.go | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/config.go b/config.go
index 2cf7f9a..0a9dde1 100644
--- a/config.go+++ b/config.go
@@ -8,6 +8,7 @@ import (
"log"
"os"
"path/filepath"
+ "runtime" "strings"
"git.sr.ht/~emersion/go-scfg"
@@ -147,11 +148,35 @@ func loadConfig(cmd *cobra.Command) *Config {
}
func defaultConfigFilename() string {
+ makeConfigFilename := func (dir string) (string) {+ return filepath.Join(dir, "hut", "config")+ }++ // on darwin systems, if `XDG_CONFIG_DIR` or `~/.config` exist, assume that+ // the user has not put them there haphazardly and default to one of them.+ // only if they do not exist fallback to `~/Library/Application Support`.+ if runtime.GOOS == "darwin" {+ xdgConfigDir, ok := os.LookupEnv("XDG_CONFIG_HOME")+ if ok {+ return makeConfigFilename(xdgConfigDir)+ }++ homeDir, err := os.UserHomeDir()+ if err != nil {+ log.Fatalf("failed to get user home dir: %v", err)+ }++ configDir := filepath.Join(homeDir, ".config")+ if _, err := os.Stat(configDir); err == nil {+ return makeConfigFilename(configDir)+ }+ }+ configDir, err := os.UserConfigDir()
if err != nil {
log.Fatalf("failed to get user config dir: %v", err)
}
- return filepath.Join(configDir, "hut", "config")+ return makeConfigFilename(configDir)}
func newInitCommand() *cobra.Command {
--
2.45.1
I don't think this is a good idea. os.UserConfigDir returns the standard
directory for the OS, XDG_CONFIG_HOME is not a standard on macOS, it's
just abused by software coming from the FreeDesktop.Org world. Having
special macOS-specific code to re-implement the FreeDesktop.Org standard
on a platform it's not supposed to be used for is incorrect.