Table of Contents
XDG Base Directory
Introduction
The XDG Base Directory Specification (let’s abbreviate it to XDG-BDS to be short) defines base directories.
For example, you probably noticed that Neovim clones plugins in $XDG_DATA_HOME which translates by default to $HOME/.local/share/.
Thanks to this specification, there is a convention for apps to use specific folders to store or look for data. For example, Neovim (and Helix, and your terminal emulator and so on) use $XDG_CONFIG_HOME to look for your configuration files.
The problem
There is tons of app who doesn’t use the XDG BDS, and so they kind of pick the place they like to put the cache or the userdate of their app (and this is annoying).
Just look at how the more time goes by, the more dotfiles there is in your $HOME.
For example, if you use a firefox based browser you have .mozilla. You use adb ? Here is your ~/.android. And of course all of your shell’s config files like .zshrc are in your $HOME too.
Quick verification
Look at your $HOME :
ls -a ~/
Doesn’t it look messy ? Pipe it into word count :
ls -a ~/ | wc -l
I have 31 files in my $HOME. And I clean it regularly. I would really like to have only my XDG Base Directories in my HOME, but as I said, some apps don’t support XDG BDS.
But fortunately, there are some programs like zsh, or git that do support XDG BDS, they just (by default) look for/create files in $HOME.
xdg-ninja
xdg-ninja is a shell script that checks if the files in your home directory support XDG BDS.
Running the script gives you a list of files that have XDG compliance, you have instructions about how to remove them from your HOME. And if a file doesn’t support XDG compliance, xdg-ninja returns a link to the issue being discussed on the internet.
Installation
Of course, on Arch-based distros it’s really easy :
paru -S xdg-ninja
sudo pacman -S glow # optional (for pretty printing)
And if you don’t have an AUR helper, just clone the repo :
git clone https://github.com/b3nj5m1n/xdg-ninja
You can then use the xdg-ninja.sh script in the folder.
Check their README for more download instructions.
Usage
I am just going to use it, and tell you what they ask me to do.
So just run the shell script, and the first things I get are warnings about variables I didn’t set in my shell’s config file. So let’s add them :
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export XDG_STATE_HOME=$HOME/.local/state
export XDG_CACHE_HOME=$HOME/.cache
And now for each file they talk about I have to follow the instruction.
For example they tell me that the $HOME/.gitconfig can be moved in ~/.config/git/config
And you only have to do this for every file they list.
Post cleaning
Now I have 20 folders in my home directory, that’s better.