Skip to content

Follow XDG Base Directory Specification on Linux/MacOS - #54

Merged
JamesDunne merged 3 commits into
alttpo:mainfrom
Renarde-dev:main
Apr 9, 2026
Merged

JamesDunne merged 3 commits into
alttpo:mainfrom
Renarde-dev:main

Conversation

@Renarde-dev

Copy link
Copy Markdown
Contributor

Tested on Linux as I do not own a Mac but it should work.

This avoid creating a .sni in the home directory by checking XDG_CONFIG_HOME first and defaulting to $HOME/.config/sni if it's not set.

To avoid loosing configs and previous logs SNI will still use $HOME/.sni if the directory already exist

If an existing $HOME/.sni directory is found use it
Check for $XDG_CONFIG_HOME first and default to $HOME/.config/sni if unset

@JamesDunne JamesDunne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, just some minor formatting and rewording to clean up. Thanks a lot!

Comment thread README.md Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
On MacOS and Linux, this folder is `~/$XDG_CONFIG_HOME/sni/` or `~/.config/sni/` with `~/.sni/` as a fallback.
On MacOS and Linux, this folder is `$XDG_CONFIG_HOME/sni/` or `$HOME/.config/sni/` with `$HOME/.sni/` as a fallback.

Comment thread cmd/sni/config/config.go Outdated
var xdgConfig = os.Getenv("XDG_CONFIG_HOME")
if xdgConfig == "" {
homeDir, _ := os.UserHomeDir()
xdgConfig = filepath.Join(homeDir,".config")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
xdgConfig = filepath.Join(homeDir,".config")
xdgConfig = filepath.Join(homeDir, ".config")

Comment thread cmd/sni/config/config.go Outdated
homeDir, _ := os.UserHomeDir()
xdgConfig = filepath.Join(homeDir,".config")
}
Dir = filepath.Join(xdgConfig,"sni")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Dir = filepath.Join(xdgConfig,"sni")
Dir = filepath.Join(xdgConfig, "sni")

Comment thread README.md Outdated

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/`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/`
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/`

@JamesDunne
JamesDunne merged commit 40d9aca into alttpo:main Apr 9, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants