Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ 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 `$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:
Expand Down
10 changes: 10 additions & 0 deletions cmd/sni/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading