关于 chezmoi-chef
chezmoi-chef 是使用 chezmoi 管理跨机器配置文件的技能,面向需要同步个人配置的用户。它涵盖模板、加密、密码管理器集成和应用配置的脚本。
主要功能
- 01跨机器管理配置文件
- 02模板化机器专属配置
- 03加密敏感文件
- 04集成密码管理器
- 05应用时运行设置脚本
适用场景
- 01在新机器初始化配置
- 02按操作系统生成配置
- 03同步加密的 SSH 密钥
- 04应用时安装所需软件
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ fonnesbeck/ shay-mwa --skill chezmoi-chef安装后在 Claude Code 中输入/chezmoi-chef确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/commands.mdpassword-managers.mdtemplates.md详细介绍
Chezmoi 点文件管理
Chezmoi 通过模板、加密和密码管理器集成,在多台计算机之间管理点文件。
快速参考
chezmoi init # Initialize
chezmoi add ~/.bashrc # Add file
chezmoi add --template ~/.zshrc # Add as template
chezmoi add --encrypt ~/.secret # Add encrypted
chezmoi edit ~/.bashrc # Edit and apply
chezmoi apply # Apply all changes
chezmoi diff # Preview changes
chezmoi update # Pull and apply
chezmoi cd # Shell in source dir
核心工作流
在新计算机上初始化
从 GitHub 获取:
chezmoi init --apply github-username
一行命令完成安装和初始化:
sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply github-username
将文件添加到管理中
chezmoi add ~/.bashrc ~/.zshrc ~/.gitconfig # Multiple files
chezmoi add -r ~/.config/nvim # Directory
chezmoi add --template ~/.bashrc # As template
chezmoi add --encrypt ~/.ssh/id_rsa # Encrypted
编辑受管理的文件
chezmoi edit ~/.bashrc # Opens source file
chezmoi edit --apply ~/.bashrc # Auto-apply after save
同步更改
chezmoi cd # Enter source directory
git add . && git commit -m "update dotfiles" && git push
exit
chezmoi apply # Apply locally
或者使用 chezmoi 的 git 封装:
chezmoi git add .
chezmoi git commit -m "update"
chezmoi git push
模板
创建特定于计算机的配置。完整指南请参阅 templates.md。
转换为模板:
chezmoi add --template ~/.bashrc
# or
chezmoi chattr +template ~/.bashrc
常见模式:
# OS-specific
{{ if eq .chezmoi.os "darwin" -}}
export PATH="/opt/homebrew/bin:$PATH"
{{- else if eq .chezmoi.os "linux" -}}
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
{{- end }}
# Hostname-specific
{{ if eq .chezmoi.hostname "work-laptop" -}}
export HTTP_PROXY="http://proxy.company.com:8080"
{{- end }}
# Distro-specific (Linux)
{{ if eq .chezmoi.osRelease.id "fedora" -}}
alias update="sudo dnf upgrade"
{{- else if eq .chezmoi.osRelease.id "ubuntu" -}}
alias update="sudo apt update && sudo apt upgrade"
{{- end }}
在 ~/.config/chezmoi/chezmoi.toml 中设置自定义变量:
[data]
email = "[email protected]"
editor = "nvim"
测试模板:
chezmoi execute-template '{{ .chezmoi.os }}'
chezmoi data # Show all variables
chezmoi cat ~/.bashrc # Show rendered output
密钥管理
集成密码管理器,避免提交密钥。所有集成方式请参阅 password-managers.md。
1Password 示例
配置(~/.config/chezmoi/chezmoi.toml):
[onepassword]
command = "op"
prompt = true
模板:
export GITHUB_TOKEN='{{ onepasswordRead "op://Personal/github/token" }}'
export AWS_ACCESS_KEY='{{ onepasswordRead "op://Work/aws/access-key" }}'
Bitwarden 示例
export API_KEY='{{ (bitwarden "item" "api-credentials").login.password }}'
pass 示例
export SECRET='{{ pass "path/to/secret" }}'
加密
加密存储在源目录中的敏感文件。
使用 age 设置
chezmoi age keygen -o ~/.config/chezmoi/key.txt
配置:
encryption = "age"
[age]
identity = "~/.config/chezmoi/key.txt"
recipient = "age1..." # Public key from keygen output
添加加密文件
chezmoi add --encrypt ~/.ssh/id_rsa
chezmoi add --encrypt ~/.aws/credentials
文件以 encrypted_ 为前缀存储,并在应用时解密。
运行脚本
在应用时执行脚本以完成设置任务。
在源目录中创建:
chezmoi cd
脚本命名规则:
run_once_install.sh- 仅运行一次run_onchange_setup.sh- 脚本更改时运行run_always.sh- 每次应用时运行
示例 run_once_install-packages.sh:
#!/bin/bash
{{ if eq .chezmoi.os "darwin" -}}
brew install ripgrep fd bat
{{- else if eq .chezmoi.osRelease.id "fedora" -}}
sudo dnf install -y ripgrep fd-find bat
{{- end }}
命令参考
完整命令列表请参阅 commands.md。
故障排除
chezmoi doctor # Check configuration
chezmoi verify # Verify targets match source
chezmoi diff # See pending changes
chezmoi status # File status overview
chezmoi --debug apply # Verbose output
重置 run_once 脚本:
chezmoi state delete-bucket --bucket=scriptState
评论
支持 Markdown