Documentation Index
Fetch the complete documentation index at: https://mintlify.com/twpayne/chezmoi/llms.txt
Use this file to discover all available pages before exploring further.
Understand how scripts work
chezmoi supports scripts that execute when you runchezmoi apply. Scripts are files in the source directory with the run_ prefix, executed in alphabetical order.
Script types
run_
Execute every time you run
chezmoi applyrun_onchange_
Execute only when script contents have changed
run_once_
Execute once per unique content version
All scripts should be idempotent (safe to run multiple times). Scripts break chezmoi’s declarative approach and should be used sparingly.
Script timing
Scripts normally run while chezmoi updates your dotfiles:before_ or after_ attributes to control timing:
Script requirements
Set environment variables
Configure extra environment variables for scripts in your config:~/.config/chezmoi/chezmoi.toml
CHEZMOI=1CHEZMOI_OS(e.g.,linux,darwin)CHEZMOI_ARCH(e.g.,amd64,arm64)- Other template data as
CHEZMOI_*variables
Don’t show scripts in chezmoi diff/chezmoi status
- Exclude from diff
- Exclude from status
~/.config/chezmoi/chezmoi.toml
chezmoi diff output.Install packages with scripts
Run a script when another file changes
Use content checksums to trigger scripts when other files change:- Template includes SHA256 hash of
dconf.iniin a comment - When
dconf.inichanges, the hash changes - Changed hash means changed script content
- chezmoi reruns the
run_onchange_script
Add
dconf.ini to .chezmoiignore so chezmoi doesn’t create it in your home directory.Clear the state of all run_onchange_ and run_once_ scripts
chezmoi tracks script execution in persistent state.
- Clear run_onchange_ state
- Clear run_once_ state
run_onchange_ scripts will run again on next chezmoi apply.