← Back to context

Comment by delusional

1 day ago

It all sounds so easy, until you learn about the XDG Base Directory Specification[1]. You're actually supposed to do a whole song and dance around a hierarchical set of environment variables, associated defaults, and resolution orders.

Interfacing with people is never easy.

[1]: https://specifications.freedesktop.org/basedir/latest/

No. Actually, it's easy. Just check for directory env or use a fallback. For example here's how you'd do this in bash:

    export CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
    export CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
    ...

XDG_*_DIRS are a bit more complicated, but nothing that can't be solved with a simple for-loop in any modern programming language.