5 ms·
Yeah, the variable is usually unset, so you’ll want to have a default value in your code. Basically something like config_dir="${XDG_CONFIG_HOME:-$HOME/.conf
by notpushkin 1y ago
Yeah, the variable is usually unset, so you’ll want to have a default value in your code. Basically something like
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/my-app"
Of course, if you decide to account for Windows / macOS conventions, it’ll be a bit trickier, but pulling in a library for that is a bit overkill, yeah.
- pasc1878 1y agoAdding a library for that is not overkill but just being polite to your users setting files where the OS suggests and not putting your ideas there,
- notpushkin 1y agoAdding a library has nothing to do with that. You can implement it yourself in a few lines of code, especially if you only need one path, like configs. You do need to research for caveats (e.g. check $XDG_CONFIG_HOME on Linux and not just put it into ~/.config) but it’s not rocket science. And if you choose to just trust library authors, you are putting their ideas there instead. There’s that Rust crate that uses XDG on macOS, for example.