Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Adding 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,


Adding 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: