Chezmoi for DotFiles

Monday, May 16, 2022

Chezmoi for DotFiles

For the past 11 years I have maintained all of my dotfiles in a repository on GitHub . In fact this was the first repository I ever created up there. The idea was that I would copy my dotfiles into a folder called .dotfiles and then copy them to the appropriate location myself. This is a bit painful at the best of times, and I just don’t do it other times.

Recently I was looking for a better tool and after looking at dotbot I decided to use chezmoi . The reason that I decided on Chezmoi is that it’s written in Go. I know that’s not much of a reason but it really has a good feature set and it’s fast.

I installed it using pacman (I use Arch by the way 😉) and started using it right away. First thing I did was initialize it with my existing repository:

$ chezmoi init https://github.com/<username>/DotFiles.git

Then I had to rename a bunch of my existing files. For example I used the name .bashrc in my existing repository but Chezmoi expects that to be dot_bashrc. Using Chesmoi is a little different than what I was used to.

sequenceDiagram participant H as home directory participant W as working copy participant L as local repo participant R as remote repo H->>L: chezmoi init H->>W: chezmoi add <file> W->>W: chezmoi edit <file> W-->>H: chezmoi diff W->>H: chezmoi apply H-->>W: chezmoi cd W->>L: git add W->>L: git commit L->>R: git push W-->>H: exit

As you can see here, you almost duplicate what you do in git with Chezmoi. You do chezmoi init to start, chezmoi add to add files and chezmoi apply to apply changes to those files after chezmoi edit, but then you do a chezmoi cd to change directory to the Chezmoi directory and you do all your usual git commands (git add ., git commit -m and git push) to get the files up to your Git repository.

The biggest problem that I have with it is you have to remember to exit after a git push. I tend to just continue on my command line journey and then when I try to end the session I have to type exit a bunch of times to get out of the virtual shells that I’m in.

Overall it’s a good solution and I’ll continue to use it and see how it goes.

Let me know what you think of Chezmoi.

Linuxdotfiles

This work is licensed under CC BY-NC-SA 4.0

Build 2022 Day 1

Software RAID on Raspberry Pi