The primary goal of chezmoi is to manage configuration files across multiple machines with different requirements. chezmoi uses Go’s text/template syntax for customization.
1
Create a machine-specific config file
Define variables that vary between machines:
[data] email = "me@home.org"
If storing private data (access tokens), ensure permissions are 0600.
2
Add the file as a template
chezmoi add --template ~/.gitconfig
This creates ~/.local/share/chezmoi/dot_gitconfig.tmpl.
3
Edit the template
chezmoi edit ~/.gitconfig
Update the file to use template variables:
~/.local/share/chezmoi/dot_gitconfig.tmpl
[user] email = {{ .email | quote }}
View available data
Test templates
chezmoi data
Shows all template variables available on your system.
# ~/.local/share/chezmoi/dot_bashrc.tmpl# common configexport EDITOR=vi# machine-specific configuration{{- if eq .chezmoi.hostname "work-laptop" }}# this will only be included in ~/.bashrc on work-laptopexport WORK_ENV=production{{- end }}
The - inside template brackets removes surrounding whitespace. This prevents extra newlines in your output.
Use .chezmoiignore templates for coarse-grained control:
README.md{{- if ne .chezmoi.hostname "work-laptop" }}.work # only manage .work on work-laptop{{- end }}
Use ne (not equal) to express “only install if”. We say “ignore unless work-laptop” instead of “install if work-laptop” because chezmoi installs everything by default.