cyberme0w's Cat logo 🐾MEOW🐾

XDG compliance, or the overwhelming lack thereof

Quick; no time for questions! Open a terminal and run:

ls -A | wc -l

That’s the number of files, folders and other tidbits that have been placed in your $HOME (with or without your blessing). Can you justify that number? Do you even know what is going on there? Personally, I like to keep my home as clean as possible, so let’s take a look and try to do a little spring cleaning.

a brief background on XDG

XDG or ā€œCross Desktop Groupā€ (previously known as X Desktop Group) is an ongoing project with the goal of improving UNIX-like operating systems’ interoperability. They have a multitude of software projects and specifications which you can find over at https://freedesktop.org. While their other projects are also interesting, the one we’re focused on during this rant is the ā€œXDG Desktop Base Directoriesā€ specification - basedir for short.

At ~800 words, basedir is a short document which provides sensible defaults for the storage location of user-specific files. It also defines some environment variables that can be set to override the default locations. There are seven base directories for the following file types:

File type Default value Environment Variable
data files $HOME/.local/share XDG_DATA_HOME / XDG_DATA_DIRS
configuration files $HOME/.config XDG_CONFIG_HOME / XDG_CONFIG_DIRS
state data $HOME/.local/state XDG_STATE_HOME
non-essential (cached) data $HOME/.cache XDG_CACHE_HOME
runtime files and other file objects (no default value) XDG_RUNTIME_DIR
executable files $HOME/.local/bin (no environment variable)

To put this information into context, let’s say we are writing an application called send-bees. It sends bees over TCP/IP to a conveniently preexisting beehive, keeps a record of how many bees were sent in a single bee-sending session, as well as the total number of bees sent. It also keeps a log of your activity per session.

It send-bees respects the basedir, it will behave something like this:

There are some benefits to this beyond than having things neatly structured. It also seems to be bothering me enough - to the point I feel it became rant-worthy. Let’s see what advantages we get from complying with the spec:

What our application should most definitely not do, is to automatically create the $HOME/.send-bees/ directory and dump everything in there, or perhaps even more perplexing, use $XDG_CONFIG_HOME, implying it complies with basedir, but then dump everything, including cache, state, runtime files, etc. into it and call it a day, effectively rendering any kind of version controlling ineffective.

Unfortunately, most applications do not follow basedir, or require setting some environment variables to look in the right places:

… and the list goes on.

Many of these have have a workaround, but that’s usually it - a hack. Meaning, every time I install a new piece of software, I have to look up if it will fill my ~/.config with junk.

There are tools like xdg-ninja which can help in cleaning up, but it would be great if more applications simply respected the spec.

*sigh*