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
- For TLDR, see Use the XDG Base Directory Specification!
- For specs, see XDG Base Directory Specification
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
- Bash
- Calcurse
- Git
- GnuPG
- Less
- Newsboat
- notmuch
- npm & pnpm
- nuget
- nvm
- rlwrap (
.*_history
: bash, ssh, trans, zsh) - translate-shell
- wget
- xsel
- radian
- R (conflicts w/ radian, TBA)
- Ollama (just models, config & ssh key are not 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™️.
- Firefox (thus Thunderbird and Zotero )
- Chromium (even though NSS supports it already…)
- itch
Mono- oh-my-tmux
- Python
- TigerVNC
- Vim (relevant RFC)
- VSCodium (
--extensions-dir
is not enough for me, and.vscode-oss/argv.json
is still needed) - w3m
- Zsh (via
$ZDOTDIR
) - ohmyzsh
- powerlevel10k
- .NET (old solution and runtime discussion)
- ADB & Android Studio (would look for
ADB_VENDOR_KEYS
as well, but~/.android
would ALWAYS get generated…) - Ren’Py (
RENPY_PATH_TO_SAVES
works on Ren’Py 7.5+ games)
Sanitizer
Python
Common methods to disable Python history are pretty hacky:
- I don’t like
chown
orchattr
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:
- 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
- Create
"$XDG_CONFIG_HOME"/python/pythonrc
:
import readline
readline.write_history_file = lambda *args: None
- Source
$HOME/.profile
byexec 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!