From 8e8434597e7bde83baca07c327924c1bb1ee189c Mon Sep 17 00:00:00 2001 From: RushLana Date: Thu, 9 Apr 2026 10:55:10 +0200 Subject: [PATCH 1/3] Follow XDG Base Directory Specification on Linux/MacOS If an existing $HOME/.sni directory is found use it Check for $XDG_CONFIG_HOME first and default to $HOME/.config/sni if unset --- cmd/sni/config/config.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/sni/config/config.go b/cmd/sni/config/config.go index 867f31a..80e95f9 100644 --- a/cmd/sni/config/config.go +++ b/cmd/sni/config/config.go @@ -86,6 +86,16 @@ func InitDir() { return } Dir = filepath.Join(Dir, ".sni") + + // Follow XDG Base Directory Specification + if _, err := os.Stat(Dir); err != nil { + var xdgConfig = os.Getenv("XDG_CONFIG_HOME") + if xdgConfig == "" { + homeDir, _ := os.UserHomeDir() + xdgConfig = filepath.Join(homeDir,".config") + } + Dir = filepath.Join(xdgConfig,"sni") + } } // make the directory if it doesn't exist: _ = os.MkdirAll(Dir, 0755|os.ModeDir) From 2b94b396873a1e48c3a46a5a799ff3594d313faf Mon Sep 17 00:00:00 2001 From: RushLana Date: Thu, 9 Apr 2026 11:04:51 +0200 Subject: [PATCH 2/3] Update README to reflect config dir changes --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 62e0a2b..507193e 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,8 @@ folder. On Windows, this folder is `%LOCALAPPDATA%\sni`. -On MacOS, this folder is `~/.sni/`. +On MacOS and Linux, this folder is `~/$XDG_CONFIG_HOME/sni/` or `~/.config/sni/` with `~/.sni/` as a fallback. +SNI use the following order when choosing a log folder : `~/.sni/` (if it already exist), `~/$XDG_CONFIG_HOME/sni/` if `$XDG_CONFIG_HOME` is not null,`~/.config/sni/` During start-up, in the console window, SNI will output where the current log file is located at: From b4cbf8a2aa46bbaf14a2e10bbe5f1894706b36aa Mon Sep 17 00:00:00 2001 From: RushLana Date: Thu, 9 Apr 2026 15:22:20 +0200 Subject: [PATCH 3/3] Fix Formating and reword README --- README.md | 7 +++++-- cmd/sni/config/config.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 507193e..eb0753b 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,11 @@ folder. On Windows, this folder is `%LOCALAPPDATA%\sni`. -On MacOS and Linux, this folder is `~/$XDG_CONFIG_HOME/sni/` or `~/.config/sni/` with `~/.sni/` as a fallback. -SNI use the following order when choosing a log folder : `~/.sni/` (if it already exist), `~/$XDG_CONFIG_HOME/sni/` if `$XDG_CONFIG_HOME` is not null,`~/.config/sni/` +On MacOS and Linux, this folder is `$XDG_CONFIG_HOME/sni/` or `$HOME/.config/sni/` with `$HOME/.sni/` as a fallback. +SNI uses the following order when choosing a config folder: +1. `$HOME/.sni/` if it already exists +2. `$XDG_CONFIG_HOME/sni/` if `$XDG_CONFIG_HOME` is set (not empty) +3. `$HOME/.config/sni/` During start-up, in the console window, SNI will output where the current log file is located at: diff --git a/cmd/sni/config/config.go b/cmd/sni/config/config.go index 80e95f9..f5a75ec 100644 --- a/cmd/sni/config/config.go +++ b/cmd/sni/config/config.go @@ -92,9 +92,9 @@ func InitDir() { var xdgConfig = os.Getenv("XDG_CONFIG_HOME") if xdgConfig == "" { homeDir, _ := os.UserHomeDir() - xdgConfig = filepath.Join(homeDir,".config") + xdgConfig = filepath.Join(homeDir, ".config") } - Dir = filepath.Join(xdgConfig,"sni") + Dir = filepath.Join(xdgConfig, "sni") } } // make the directory if it doesn't exist: