Benefits: Direct file editing, works with any editor, can edit multiple files.3. Open source directory in editor:
chezmoi edit # Opens source directory
Benefits: Works with IDEs, edit multiple files at once.4. Edit target, then re-add:
vim ~/.bashrcchezmoi add ~/.bashrc # or: chezmoi re-add
Benefits: Familiar workflow, edit in place.Note:re-add doesn’t work with templates.5. Edit target, then merge:
vim ~/.bashrcchezmoi merge ~/.bashrc
Benefits: Resolve conflicts with a merge tool.
What happens if I edit a dotfile without using `chezmoi edit`?
If you edit ~/.zshrc directly (without using chezmoi), nothing breaks immediately:Before running chezmoi apply:
Your modified ~/.zshrc remains in place
Changes persist until you run chezmoi apply
When you run chezmoi apply:
chezmoi detects that ~/.zshrc has changed
You’ll be prompted what to do
Options: overwrite, keep current, or merge
To resolve differences:
# Option 1: Update source state with current filechezmoi add ~/.zshrc# Option 2: Use merge tool to resolvechezmoi merge ~/.zshrc# Option 3: See differenceschezmoi diff
Best practice: Use chezmoi edit to avoid conflicts, or configure auto-apply to see changes immediately.
How can I tell what dotfiles aren't managed by chezmoi?
Use chezmoi unmanaged to see all files that exist in your home directory but aren’t managed by chezmoi:
# List all unmanaged fileschezmoi unmanaged# List only unmanaged dotfiles (starting with .)chezmoi unmanaged | grep '^\.'# Search for specific patternschezmoi unmanaged | grep config
Add multiple files at once:
# Add specific fileschezmoi add ~/.vimrc ~/.tmux.conf# Add an entire directorychezmoi add ~/.config/nvim# Add multiple directorieschezmoi add ~/.config/kitty ~/.config/alacritty
How can I tell what dotfiles are currently managed by chezmoi?
Use chezmoi managed to list all files managed by chezmoi:
# List all managed fileschezmoi managed# List managed files in a specific directorychezmoi managed | grep .config/nvim# Count managed fileschezmoi managed | wc -l
By default, chezmoi only manages files you explicitly add. To ignore files in your source directory, use .chezmoiignore.Create .chezmoiignore in your source directory:
Then use chezmoi to manage Atuin’s configuration file.
How do I install prerequisites for templates?
If your templates depend on external tools (like curl, jq, etc.), install them with a run_before script:
run_before_00-install-prerequisites.sh
#!/bin/bashset -eu# Install curl if not presentif ! command -v curl >/dev/null; then sudo apt update sudo apt install -y curlfi# Install jq if not presentif ! command -v jq >/dev/null; then sudo apt install -y jqfi
Important: Don’t make this script a template (no .tmpl extension), or it will be evaluated before the prerequisites are installed.Inject data via environment variables:If you need to pass data to non-template scripts:
How do I run a script when an external repo changes?
Use a run_onchange_after_*.tmpl script that includes the HEAD commit:
run_onchange_after_emacs_d.tmpl
#!/bin/bash# This comment includes the current HEAD, so the script runs when it changes# {{ output "git" "-C" (joinPath .chezmoi.homeDir ".emacs.d") "rev-parse" "HEAD" }}echo "~/.emacs.d updated, running setup..."~/.emacs.d/bin/doom sync
How it works:
The template output includes the git HEAD commit hash
When the external repo updates, HEAD changes
chezmoi detects the script content changed
The script runs automatically
How do I run a script periodically (daily, weekly)?
Use a run_onchange_*.tmpl script with the current date/time truncated to your desired period.Run daily:
run_onchange_daily.tmpl
#!/bin/bash# This comment changes daily, triggering the script# {{ now | date "2006-01-02" }}echo "Running daily tasks"# Your daily tasks here
Run weekly:
run_onchange_weekly.tmpl
#!/bin/bash# Week number (changes weekly)# {{ output "date" "+%V" | trim }}echo "Running weekly tasks"# Your weekly tasks here
Package managers: If you installed via a package manager (brew, apt, etc.), completions may already be installed.
How do I use tools installed with Flatpak?
Command-line tools installed with Flatpak must be run with flatpak run. There are two approaches:Approach 1: Wrapper script (recommended):Create a wrapper with the same name as the command:
~/bin/keepassxc-cli
#!/bin/bashflatpak run --command=keepassxc-cli org.keepassxc.KeePassXC -- "$@"
Make it executable:
chmod +x ~/bin/keepassxc-cli
Ensure ~/bin is in your $PATH. Now chezmoi can find and run keepassxc-cli normally.Approach 2: Direct configuration:For tools with .command and .args config options: