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 devtoolsrun_once_01_install_homebrew
β Installs Homebrew if it's not already installedrun_onchange_after_brew-bundle
β To runbrew bundle
whenever theBrewfile
changesrun_onchange_after_configure-macos
β To configure a bunch ofmacOS
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:
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.
What my chezmoi setup achieves
macOS Setup
As a long-time computer user, my ideal macOS configuration is comprised of years of small tweaks here and there. Once set, those tweaks are normally forgotten until such time as I get a new machine, or use someone else's computer π .
Some of the highlights include:
- Installing Xcode's command line tools
- Installing Homebrew as well as all of my Homebrew packages
- Finder config:
- Disable transparency
- Disable window animation
- Show hidden files by default
- Set window title to full POSIX file path of current folder
- When performing a search, search the current folder by default
- Disable the warning when changing a file extension
- Show the ~/Library folder
- Mail.app:
- Copy an email address as [email protected]
instead of Hello <[email protected]>
- Shell
- Set Fish as the default shell
Config
Fish:
- Set
git
aliases - Set default prompt as starship
Set a bunch of other aliases (including 2 to fix some of macOS's flakier processes)
Ruby
General
- Set a global tool-version file for Mise
- Remap a couple of keys with Karabiner:
- Caps Lock to delete
- Switch option and command on my non-Apple keyboard