XDG Base Dir #
XDG Base Directory is a specification to help manage “well-known” user-directories, like where to store music files, or where a developer can store cache for their app. This is starting to become more adopted on linux environments and becoming more of the norm.
On macOS, something similar has always existed, but may, or may not, be followed as closely. Examples of these directories on macOS is ~/Library/Application Support/<bundle_id> for storing files specific to your app, or ~/Library/Cache/<bundle_id> to store cache. Note though that bundle id is a part of the path. macOS provides API to easily get to these directories for App Developers but doesn’t provide an easy way for script writers or non XCode Developers to access these paths.
The specification can be viewed here: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Why does this matter? #
Personally I like to use it to keep my files organized. Currently, the Home directory is dumping ground for a lot of config, cache, and state files, since its usually the default path a developer will use. However, most applications support storing these files in an alternate directory, either by just having XDG_CONFIG_HOME environment variable set, or sometimes by setting a specific environment variable for that app that tells it where to store their files. This helps to:
- reduce clutter in the home directory
- sync configs across systems