📝 Managing dotfiles.

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 - Then, 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 chezmoi apply.

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:

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.

Published 22 January, 2023

© 2023 Daniel Nitsikopoulos. All rights reserved.