Maintaining dotfiles with chezmoi View article history Edit article

Published: , Updated:
Talks about: <a class="post-tag post-tag-chezmoi" href="/tags/chezmoi">chezmoi</a>, and <a class="post-tag post-tag-dotfiles" href="/tags/dotfiles">dotfiles</a>

To make it easier managing many dotfiles with chezmoi, a shell function similar to the one below can be used:

function m-dotfiles-ok {
    # public
    chezmoi add ~/.config/zsh --recursive
    chezmoi add ~/.config/sway --recursive
    chezmoi add ~/.config/tmux --recursive
    chezmoi add ....

    # secrets
    chezmoi add --encrypt ~/.config/npm/npmrc
    chezmoi add --encrypt ~/.ssh/id_rsa
    chezmoi add --encrypt ...
}

Whenever you feel happy with your current setup, just call m-dotfiles-ok to push changes into the chezmoi source directory. Files will automatically be encrypted with gpg and committed/pushed into a Git repository if you have done the necessary configuration beforehand.

In general, editing your dotfiles directly as explained in the second option of the FAQ seems easier though. Refactoring your dotfiles is especially easy when the exact_ prefix is used for directories. As explained in the documentation, all files that are not managed by chezmoi will be removed, therefore your configuration will always match what is in your source directory.