It's not often that I get a new computer, but on the odd occasion that I do, I like to have all of my config prepared and ready to copy over!
To achieve this, I am using chezmoi and GitHub to keep an up to date snapshot of my dotfiles. My previous tool of choice for managing dotfiles was rcm, but chezmoi offers things like password manager integration, scripts, and templates to customise dotfiles based on the machine I am setting up, making it just that little bit more useful.
The initial setup of chezmoi is super straightforward, just:
chezmoi init chezmoi add ~/.my-first-file chezmoi cd # follow your usual git workflow to add a remote and push
Then, to pull down and apply your dotfiles on another machine, run:
chezmoi init --apply $github_username
From here, the workflow of adding and updating files is essentially:
- Edit the source file on your machine
chezmoi add ~/.file to commit and push to GitHub
The chezmoi FAQ lists a couple of other ways you can keep a file in sync, including
chezmoi edit and
chezmoi merge, but I have found
add to be the simplest.
Chezmoi also makes it simple to run scripts when you run
You can decide whether a script is
run_once_ when you first run
chezmoi apply, or
run_onchange_, which will run every time, provided the file has changed.
The scripts I have at the time of writing are:
run_once_00_install-xcode-devtools— Does what it says on the tin, installs Xcode's devtools
run_once_01_install_homebrew— Installs Homebrew if it's not already installed
run_onchange_after_brew-bundle— To run
brew bundlewhenever the
run_onchange_after_configure-macos— To configure a bunch of
macOSand LaunchBar defaults.
Having a look through the chezmoi docs, you'll see there's a bunch more you can configure to meet your specific requirements, but hopefully this has provided a brief insight in to what is possible, and how easy it is to get started with a simple setup.