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:

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:

  • 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 bundle whenever the Brewfile changes
  • run_onchange_after_configure-macos β€” To configure a bunch of macOS and 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.

Once the initial setup is done, the day-to-day to maintain your dot files will look like this:

A short flow chart showing how dot files can be managed with chezmoid

SSH keys

My SSH keys are the one thing that are not managed by chezmoi. For that I make use of 1Password. All my keys are stored in its vault and are then made available to the ssh-agent via 1Password's ssh agent integration. This makes it super easy to generate a bunch of keys for different services rather than using a single key for everything.

Published

by Daniel Nitsikopoulos

in posts

Tagged

Β© 2010 - 2024 Daniel Nitsikopoulos. All rights reserved.

πŸ•ΈπŸ’  →