chezmoi
Many of us use more than one computer for work. And we use, if not identical, then overlapping sets of applications and tools that need the same configuration on every machine:
gitvim/nvimtmuxeditorconfigkarabinerzsh- and others.
These configuration files are usually called dotfiles — their names start with a dot (.), which in the world of Unix-like systems makes a file hidden.
These files describe the configuration of the utilities you use. They need to be kept current across all of your machines.
The simplest solution is most often creating a git repository named dotfiles and dumping the files into it as is.
That brings up a few problems:
- It’s neither convenient nor safe to initialize such a repository at the root of your home directory:
- The chance of accidentally publishing secrets — say, your private key — goes up.
- Working with a repository where most files and directories are either ignored or not in the index is very inconvenient.
- If you version individual files, every modification has to be propagated manually to the repository and to the other machines along their respective paths.
Dotfile managers
There are plenty of dotfile managers out there, but a while back I settled on chezmoi.
Why is this manager convenient?
- It still uses
gitunder the hood. That means there’s no new tool to learn. - Only files explicitly added by the user fall under its responsibility.
- It has a very simple command-line interface. A single
chezmoi applyis enough to pull in any fresh changes, if there are any. - It supports file templating, which means you can rely on, say, the hostname when assembling certain blocks of a file —
for example the
usersection of.gitconfig. - It supports command-line interfaces for accessing secrets, for example
bitwarden-cli. That lets you keep secrets separate from the dotfiles themselves and template them in at fetch time.
Below is a short example of how to get started with chezmoi. For details, refer to the official documentation.
# Create a repository for your dotfiles (default: ~/.local/share/chezmoi)
chezmoi init
# Track a file
chezmoi add ~/.vimrc
# cd into the repository to add the file under version control if you want it available on other machines
chezmoi cd
git add .
git ci -m "Add .vimrc"
# Publish the changes
git remote add origin https://github.com/$GITHUB_USERNAME/dotfiles.git
git push -u
Your personal dotfiles repository can be private, or hosted on any service you like.
The first steps with chezmoi may feel a bit non-obvious or unfamiliar. But the deeper you go and the more actively you
use this dotfile manager’s features, the more it opens up.
Good luck syncing!