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.
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.
If send-bees respects the basedir, it will behave something like this:
beehive address, log policy,
etc. under $XDG_CONFIG_HOME/send-bees/config (The file name itself is not specified, so anything goes
here, e.g. send-bees.config).$XDG_STATE_HOME/send-bees/current.$XDG_RUNTIME_DIR/send-bees/beehive-socket (once again, file names donāt matter
- folders do)$XDG_CACHE_HOME/send-bees/session, which later
may get dumped to the total bees fileThere 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:
$XDG_CONFIG_HOME contains only text files and can sensibly be version-controlled with gitcp -r /backup/.config ~ (or git
clone git@host:user/config .config if you are cool)$XDG_CACHE_HOME can be moved to a tmpfs
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:
~/.mozilla/~/.android, even though it allows you to configure what folders it should
look in~/.{language} folders$XDG_CONFIG_HOME/app/⦠and the list goes on.
Many of these 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*