Manage dotfiles using chezmoi. Use when creating, modifying, or deploying dotfiles, shell functions, or configuration files in this repository.
This skill helps manage dotfiles using chezmoi in this repository.
All dotfiles are managed in ~/.local/share/chezmoi which is a git repository synced to GitHub at https://github.com/craigtkhill/dotfiles.git.
When creating or modifying dotfiles, you MUST follow this exact order:
Check for drift before every new task ā no exceptions
Run this before starting any new task in this repo, not just once per session ā other processes (e.g. Obsidian) edit tracked files live and can create drift mid-session:
chezmoi status
Empty output ā proceed. Any output ā re-add every drifted file immediately (paths from chezmoi status are home-relative), regardless of whether it's related to the current task:
chezmoi status | awk '{print $2}' | while read -r f; do chezmoi re-add ~/"$f"; done
The pre-commit hook blocks commits when home directory files differ from the chezmoi source. Never wait to be asked or reminded.
Navigate to chezmoi source directory
cd ~/.local/share/chezmoi
Create or edit files using chezmoi naming conventions
dot_ prefix for dotfiles (e.g., dot_gitconfig ā ~/.gitconfig)dot_config/fish/functions/ ā ~/.config/fish/functions/)~/.local/share/chezmoi or use chezmoi edit <target-path>Apply changes to home directory
chezmoi apply
# or for specific file:
chezmoi apply ~/.config/fish/functions/myfile.fish
Commit and push to GitHub
cd ~/.local/share/chezmoi
git add .
git commit -m "your message"
git push origin main
Verify it's managed
chezmoi managed | grep myfile
chezmoi status - Show what has changedchezmoi diff - Show detailed differenceschezmoi managed - List all managed fileschezmoi apply - Apply changes from dotfiles to home directorychezmoi apply --force - Force apply, overriding conflictschezmoi add <file> - Add a file to chezmoi trackingchezmoi re-add <file> - Re-add a tracked fileFish automatically loads functions from ~/.config/fish/functions/. Each function must be in its own file named functionname.fish.
After adding new fish functions:
~/.config/fish/functions/If you want to add an existing file from your home directory to chezmoi:
chezmoi add ~/.config/fish/functions/myfile.fish
This will copy the file to ~/.local/share/chezmoi with proper naming and make it managed.
Tools are split across two files:
cargo-update).When adding a new CLI tool:
brew info <tool> --json | python3 -c "import sys,json; print(json.load(sys.stdin)[0]['versions']['stable'])"curl -s https://crates.io/api/v1/crates/<tool> | python3 -c "import sys,json; print(json.load(sys.stdin)['crate']['newest_version'])"ā DON'T: Edit files directly in ~/.config/fish/ without updating chezmoi
ā DON'T: Forget to commit and push changes to GitHub
ā DON'T: Retry git commit immediately after a hook failure without re-running chezmoi apply
end-of-file-fixer rewrite files in the working tree on failure, silently re-creating drift against home. Always chezmoi apply && chezmoi status (must be empty) before retrying.ā DON'T: Trust what's staged after a failed commit attempt
git add -A can leave unrelated files staged, bundling them into your next, supposedly-separate commit. Run git diff --cached --stat and confirm only intended paths before committing.ā DON'T: Write the commit message before your final check of what's staged
chezmoi apply running between staging and committing can change the staged diff, making an earlier-drafted message stale. Run git diff --cached --stat immediately before git commit and confirm it still matches the message ā if not, stop and reconcile before committing.ā
DO: Edit in ~/.local/share/chezmoi ā Apply ā Commit ā Push