How I Manage My Dotfiles, Revisited
2026-11-29
Five years later
In 2021, I wrote How I Manage My Dotfiles.
The system was simple: a shell script called dotfiles and a plain-text configuration file describing which symbolic links the script should create.
I have been using that system ever since, and it has held up well. But one gap has become harder to ignore over time.
The configuration file’s tag option let me choose which dotfiles to link on a given machine. What it could not do was vary what is inside those dotfiles. This matters most for work.
For example, on my work machine, I use a different email for Git than the one I use for personal projects. I also have scripts and configuration that only make sense in a work context. None of this belongs in my personal dotfiles project.
Until recently, my options were to commit work-specific configuration into my personal repository or to edit files by hand on my work machine. Neither appealed to me.
Adding override hooks
The fix turned out to be small. Each of my main dotfiles now loads an optional, machine-local file, usually as its very last step. Since it is loaded last, anything in the local file adds to or supersedes what came before it. If the local file does not exist, it is simply skipped.
| Dotfile | Local file | Purpose |
|---|---|---|
.bashrc |
~/.bash_env.local |
PATH and environment variables (all shells) |
.bashrc |
~/.bashrc.local |
Aliases, functions and prompt (interactive only) |
.gitconfig |
~/.gitconfig.local |
Git settings |
.tmux.conf |
~/.tmux.local.conf |
tmux settings |
.vimrc |
~/.vimrc.local |
Vim settings |
Each application already has a way to include another file, so the hooks themselves are only a line or two.
In .gitconfig, it is an include:
[include]
path = ~/.gitconfig.local
In .tmux.conf, the -q flag keeps tmux quiet if the file is missing:
source-file -q ~/.tmux.local.conf
In .vimrc, the source is guarded by a readability check:
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
Bash gets two hooks rather than one.
My .bashrc exits early for non-interactive shells, so anything after that point never applies to non-interactive shells, such as commands run over ssh.
~/.bash_env.local is sourced before the early exit, which makes it the right place for PATH and environment variables.
~/.bashrc.local is sourced at the very end, which makes it the right place for aliases, functions and prompt tweaks.
# Machine-specific PATH and environment variables (applies to all shells)
[[ -r "$HOME/.bash_env.local" ]] && . "$HOME/.bash_env.local"
...
# Machine-specific settings that add to or supersede the above
[[ -r "$HOME/.bashrc.local" ]] && . "$HOME/.bashrc.local"
With these in place, using a different Git email at work is just a matter of placing a ~/.gitconfig.local on my work machine:
[user]
email = idian.al@work.com
A more portable configuration file
To make the hooks truly useful, I also had to revisit the configuration file. In 2021, it looked like this:
linux /home/idianal/dotfiles/git/gitconfig /home/idianal/.gitconfig
linux /home/idianal/dotfiles/vim/vimrc /home/idianal/.vimrc
macos /Users/idianal/dotfiles/bash/bashrc /Users/idianal/.bashrc
Every path was absolute.
This meant the configuration only worked if the repository was cloned to one exact location and my username was exactly idianal.
It also meant the linux and macos sections were near duplicates of each other, differing only in their path prefixes.
The dotfiles script now resolves relative paths:
- A relative target is resolved against the directory containing the configuration file.
- A relative link (or one starting with
~/) is resolved against$HOME. - Absolute paths are used as-is.
So the two sections collapsed into one:
base bash/bashrc .bashrc
base bash/bash_aliases .bash_aliases
base bash/bash_profile .bash_profile
base git/gitconfig .gitconfig
base tmux/tmux.conf .tmux.conf
base vim/vimrc .vimrc
The repository can now be cloned anywhere, by any user, and the configuration still works.
Putting it together
Where do the local files come from? I could create them by hand on each machine, but that would bring back the very problem I was trying to solve.
Instead, I keep them in a separate work repository.
That repository includes my personal dotfiles as a Git submodule, along with its own configuration file that links the *.local files into place.
Since the configuration file now uses relative paths, the same dotfiles script works for both:
# Link my personal dotfiles
$ base/dotfiles --file base/config --tag base
# Link my work additions and overrides
$ base/dotfiles --file config --tag work
The first command sets up my usual environment. The second layers work-specific configuration on top of it.
The result is a clean separation:
- My personal dotfiles stay generic. They know that a local override might exist, but nothing about what it contains.
- My work configuration lives entirely in the work repository. It never leaks into a public project.
- There is still only one script to maintain.
Still simple
When I wrote the original post, I listed minimal dependencies as one of the key benefits of my approach.
I am happy to say that this has not changed.
The hooks rely on nothing more than each application’s own ability to include another file, and the dotfiles script is still a short Bash script.
It is a small change, but it solved the one problem I kept running into. I expect this setup to serve me well for another five years.