我的 dotfiles,chezmoi 管理。
- 多机同步(macOS / Fedora),按 profile 区分 work / personal
- 新机器一行命令开荒,自动装齐 CLI 工具
- 模板化
gitconfig,敏感配置走 Bitwarden
| 工具 / 文件 | 部署到 | 内容 |
|---|---|---|
dot_zshrc |
~/.zshrc |
通用:zinit + fzf + history + setopts + 各种 hook |
dot_zshrc.work |
~/.zshrc.work |
work 专属:CNB MR push aliases、Android SDK、Flutter pub-cache、mise activate |
dot_gitconfig.tmpl |
~/.gitconfig |
git 配置(user 字段按机器渲染) |
dot_config/ghostty/config |
~/.config/ghostty/config |
Ghostty 终端 |
dot_config/zellij/config.kdl |
~/.config/zellij/config.kdl |
Zellij 多路复用 |
dot_config/starship.toml |
~/.config/starship.toml |
Starship 提示符 |
dot_config/nvim/ |
~/.config/nvim/ |
LazyVim 配置(init.lua + lua/ 等;lazy-lock.json 不同步,各机自维护) |
run_onchange_before_install-packages.sh.tmpl |
(脚本) | 按 OS 自动装齐 CLI 工具,内容变化时自动重跑 |
工具栈(脚本会自动装):bat / bitwarden-cli / chezmoi / direnv / eza / fd / fzf / gh / git-delta / lazygit / mise / neovim / pnpm / ripgrep / starship / zellij / zoxide,macOS 另装 Ghostty。
# 一行:装 chezmoi、clone、首次 init、自动装齐 brew 工具、部署 dotfiles
sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply zhndsh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply zhnd脚本会用
dnf装官方源里有的、用mise.run安装器装 mise。zellij / bitwarden-cli 需要手动装(脚本会提示链接)。
Machine profile: [personal/work]
Git user.name:
Git user.email (留空则不设置全局):
填写结果存到 ~/.config/chezmoi/chezmoi.toml,之后不再询问。修改:
chezmoi edit-config # 改本机变量
chezmoi apply # 重新渲染部署chezmoi edit ~/.zshrc # 在 $EDITOR 里打开源文件
chezmoi apply # 部署
# 或者一气呵成:
chezmoi edit --apply ~/.zshrcnvim ~/.zshrc # 直接改部署的副本
chezmoi add ~/.zshrc # 把改动同步回 sourcechezmoi diff # 仓库 → ~ 的待应用差异
chezmoi diff ~/.zshrc # 只看某个文件
chezmoi cat ~/.zshrc # 看仓库源(.tmpl 会按本机变量渲染后输出)
chezmoi managed # 列出所有纳管文件
chezmoi status # 摘要chezmoi cd # 切到 ~/.local/share/chezmoi(带 git)
git add . && git commit -m "..." && git push
exit
chezmoi update # 在另一台机:拉远端并自动 apply| 前缀 / 后缀 | 含义 |
|---|---|
dot_xxx |
部署为 ~/.xxx |
xxx.tmpl |
模板,渲染后部署 |
run_onchange_before_xxx.sh.tmpl |
内容哈希变化时执行,在文件部署之前 |
private_dot_xxx |
部署后权限 0600 |
encrypted_dot_xxx |
仓库里加密存储,部署时解密 |
仓库里有些内容只有 work 才需要。机制:
- 整段隔离:work 专属内容放独立文件
dot_zshrc.work .chezmoiignore是模板,按 profile 决定是否 ignore:{{- if ne .profile "work" }} .zshrc.work {{- end }}- 主 .zshrc 末尾条件 source:
[[ -f ~/.zshrc.work ]] && source ~/.zshrc.work [[ -f ~/.zshrc.personal ]] && source ~/.zshrc.personal
效果:personal 机不部署 .zshrc.work,那行 source 自动跳过;work 机正常加载。
直接编辑 ~/.zshrc.work → chezmoi add → push。
chezmoi cd
touch dot_zshrc.personal
# 改 .chezmoiignore 加一行:{{- if ne .profile "personal" }} .zshrc.personal {{- end }}.tmpl 文件里可用:
| 变量 | 来源 | 值 |
|---|---|---|
{{ .profile }} |
首次 init 选择 | "work" / "personal" |
{{ .git.name }} |
首次 init 输入 | git user.name |
{{ .git.email }} |
首次 init 输入 | git user.email(可空) |
{{ .chezmoi.os }} |
内置 | "darwin" / "linux" |
{{ .chezmoi.hostname }} |
内置 | 主机名 |
{{ .chezmoi.username }} |
内置 | 系统用户名 |
例:
{{- if eq .profile "work" }}
# work 专属
{{- end }}
{{- if eq .chezmoi.os "linux" }}
# Linux 专属
{{- end }}
不想把 token / API key 明文存仓库时用:
bw login # 一次性
export BW_SESSION=$(bw unlock --raw) # 每次新 shell 解锁(或写进 .zshrc)模板里取值:
{{ (bitwardenFields "item" "GitHub PAT").token.value }}
chezmoi apply 时自动拉取并渲染。
| macOS | Fedora | 说明 | |
|---|---|---|---|
| 自动 brew/dnf 装包 | ✅ | ✅ | Fedora 默认源缺的会用脚本/二进制装 |
| Ghostty | ✅ cask | ❌ | Linux 上不需要(用别的终端) |
| Zellij | ✅ brew | Fedora 没在默认源,提示下载二进制 | |
| Bitwarden CLI | ✅ brew | 同上 | |
| 配置文件 | ✅ | ✅ | 全部跨平台 |
chezmoi init # 不带 URL,等同于重新渲染 chezmoi.toml不会重 clone,只重渲染本机配置文件。
zellij 的 serialize_pane_viewport 在重绘频繁的 TUI 里有性能开销。本仓库已禁用,仅保留 session_serialization 做 layout 恢复。
编辑 ~/.config/chezmoi/chezmoi.toml,改 profile 后 chezmoi apply。
Conventional Commits:feat: / fix: / refactor: / chore: / docs:。