Keep $HOME Clean via XDG Base Directory

Foreword

I came across Dotfile madness (2019) on Hacker News today, and found How I Keep My Home Directory Clean & XDG Base Directory on Arch Wiki.

This serves as a reminder of how to make $HOME (mostly) clutter-free, thus making Manage Dotfiles Using Bare Git Repo easier.

XDG Base Directory

Show, don’t tell:

# Use the XDG Base Directory Specification
# TLDR: https://xdgbasedirectoryspecification.com/
# Spec: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
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"

Sterilization

Most are available in XDG Base Directory on Arch Wiki already.

Partially/Fully Supported

Hardcoded

Many softwares are old enough to arrogantly ignore XDG Base Directory Specification and get away with it. Exempli gratia, Firefox has a 20-year-old bug report regarding Support for the Freedesktop.org XDG Base Directory Specification , and it’s updated just a few weeks ago as of writingupdating!

The list contains only a small fraction of blessed packages that might show some respect to the spec soon™️.

Sanitizer

Python

Common methods to disable Python history are pretty hacky:

  • I don’t like chown or chattr solution as .python_history is still present.
  • Removing ~/.python_history by creating ~/.pythonrc is just funny.

Quoted from a comment regarding this solution :

So I get to replace one turd in my home directory with another

I combine the answers of How can I disable the new history feature in Python 3.4? and enhance it by doing the following:

  1. Add these in $HOME/.profile(.bashrc or .zshrc works too):
export PYTHONPYCACHEPREFIX="$XDG_CACHE_HOME"/python
export PYTHONUSERBASE="$XDG_DATA_HOME"/python
export PYTHONSTARTUP="$XDG_CONFIG_HOME"/python/pythonrc
  1. Create "$XDG_CONFIG_HOME"/python/pythonrc:
import readline
readline.write_history_file = lambda *args: None
  1. Source $HOME/.profile by exec zsh, done.

Vim

Follow the instruction on Arch Wiki, and move the original files respectively:

$XDG_CONFIG_HOME/vim
├── colors
└── vimrc

$XDG_DATA_HOME/vim
└── spell
    ├── en.utf-8.add
    └── ...

Show-off

$ ls -a1
.bashrc
.cache/
.config/
.dotfiles/
.gitignore
.local/
.profile
.ssh/
.tmux.conf -> .config/tmux/oh-my-tmux/.tmux.conf
.tmux.conf.local -> .config/tmux/tmux.conf.local*
.zshenv
downloads/
music -> my-music-dir
projects/
scripts -> my-script-dir

It’s possible to move .bashrc, .dotfiles, .tmux* and those symlinks elsewhere as well. I just don’t bother to do it. If done properly, $HOME could become:

$ ls -1
projects/

$ ls -a1
.cache/
.config/
.local/
.profile
.ssh/
projects/

OCD Gospel!

Vinfall's Geekademy

Sine īrā et studiō