Today, as alluded in the Organizing my ~/.zshrc file
post, I got to revive my chezmoi
usage. This was mostly because I finally set up my Arch Linux box with an NVIDIA RTX 3080 GPU that I could ssh into from my Mac, and I wanted to sync my dotfiles between the two machines.
I figured I would learn more about chezmoi while I was at it, so that I could actually, responsibly use it manage my dotfiles.
So first, some concepts
in chezmoi, explained in a way that I understand:
- The destination (directory) is the root folder that all the chezmoi’s paths are relative to. Mine (and presumably the default) is the home directory. This doesn’t mean
chezmoiwill manage everything in the home folder. You tell whatchezmoimanages using thechezmoi addcommand. - The source (directory) is where the tracked/managed dotfiles live. Mine (and default) is
~/.local/share/chezmoi. You can get here by runningchezmoi cd. Here are some things I have:
dot_config dot_ideavimrc README.md
dot_condarc dot_tmux.conf
dot_gitconfig dot_zshrc.tmpl
- Everything in the
chezmoi cddirectory is the source state. According to the concepts page , these include templates (like thedot_zshrc.tmpl), regular files (likedot_ideavimrc) and directories (likedot_config). - The target is a file, directory, or symlink in the destination directory, which I believe you can see via
chezmoi managed.
The Three States
The target has three versions or states.
| What it is | How to see | |
|---|---|---|
| Source State | dot_zshrc.tmpl | cat "$(chezmoi source-path ~/.zshrc)" |
| Target State | The template rendered for this machine | chezmoi cat ~/.zshrc |
| Destination State | Actual file on disk right now | cat ~/.zshrc |
So the source AND machine data (MacOS or Arch Linux) determine the target, and chezmoi apply creates the actual destination file, if I’m understanding correctly.
The chezmoi diff ~/.zshrc would show me the difference between Target and Destination (right now it is empty because everything is synced). I believe the “correct” way to edit dotfiles that are managed by chezmoi is by chezmoi edit FILE, and then chezmoi apply would apply that to destination file.
If I do accidentally edit like nvim ~/.zshrc, then I should see the difference via chezmoi status or chezmoi diff. Apparently to “check this into” chezmoi, I should use chezmoi re-add FILE (for plain files) or chezmoi merge ~/.zshrc for templates. In the Arch Linux box, I can use chezmoi update to get the latest configs.
Overall, chezmoi has very much a git-like feeling for me, and if that is indication of anything, using it more would help me actually understand better. Will come back with more TIL if I have any better insights on chezmoi. :)