59e2356f5c
Daily ff subcommands never updated the repo; only `ff update` did. Add a pouch-style interval auto-update at the ff entry (default 24h), skip dirty/fail/timeout without aborting the current command, and cover the skip/pull cases with a fish regression.
5.9 KiB
5.9 KiB
dotfile 维护约定
个人 dotfiles 仓库(~/.dotfile)。本文件供 AI coding agent 与维护者共用:新增或改造配置/脚本时请遵循以下规则。
常用命令
ff script -h # 列出 script/ 下所有脚本及说明
ff script <name> # 运行脚本
make -f Makefile.scripts <name> # 同上(make 入口)
ff region # 切换 CN_REGION(国内/国外镜像)
ff reload # 重载 fish 配置
ff update # 立即 git pull origin main 并 reload
fish fish/tests/ff-auto-update.fish # ff 自动更新回归
目录职责
| 路径 | 用途 |
|---|---|
script/ |
可执行脚本(安装、初始化、工具);已加入 fish PATH |
script/common/ |
脚本共享片段(help.sh、os-arch.sh) |
fish/default.fish |
共享 fish 配置(进 git) |
~/.config/fish/config.fish |
本机 wrapper,仅 source default.fish + 可选 custom.fish |
fish/functions/、fish/completions/ |
fish 函数与补全;fish-init 会软链到 ~/.config/fish/ |
git/、nvim/、tmux/、zsh/、cursor/、ghostty/ 等 |
各工具真实配置,由对应 *-init 软链到系统路径 |
mise/config.toml |
跨机器共享;mise-install 链到 ~/.config/mise/conf.d/dotfile.toml。本机工具在 ~/.config/mise/config.toml |
Makefile.scripts |
make <script-name> 运行 script/<name>.sh |
脚本命名
*-install.sh:安装软件/运行时(如docker-install、nvim-install、mise-install)*-init.sh:把 dotfile 配置软链接到系统默认路径(如git-init、fish-init、nvim-init)- 工具脚本:动词或名词(
dns-clean、scan-ip、nosudo、docker-group、dirsize) - 文件名与
make/ff script子命令一致(无扩展名调用)
新增脚本 checklist
- 放在
script/,shebang + 一行#功能描述(供ff script -h自动展示) source "$SCRIPT_DIR/common/help.sh",实现usage(),支持-h/--help- 需要平台判断时用
script/common/os-arch.sh - 依赖国内镜像的安装脚本读取
CN_REGION=1(toggle-region/ff region) - 若需 fish 补全,更新
fish/completions/ff.fish(描述从脚本头注释提取)
init 脚本模式
- 目标路径已有文件:先备份(
*.bak或*.backup.<timestamp>),再ln -sf指向~/.dotfile/... - 已存在且指向正确的软链:幂等跳过
- 示例:
git-init→~/.gitconfig;nvim-init→~/.config/nvim;ghostty-init→ 各平台 Ghostty 配置目录 - fish-init 特殊:不链整个
config.fish,只在顶部插入source ~/.dotfile/fish/default.fish,并链functions/、completions/
install 脚本模式
- 优先用系统包管理器(brew/apt),其次官方安装脚本或 Release 二进制到
~/.local/bin - Debian/Ubuntu 安装类脚本应支持
CN_REGION切换镜像(参考docker-install.sh) - 需要 root 的脚本在 usage 里写
sudo,不要静默假设 - mise:共享
mise/config.toml链到~/.config/mise/conf.d/dotfile.toml;mise use -g写本机~/.config/mise/config.toml,不进 git。旧的指向仓库的全局软链由mise-install解开
Fish / ff 入口
- 跑脚本:
ff script <name>或ff s <name>(走execute-script.fish) - 列脚本:
ff script -h - 新增
ff子命令时:改fish/functions/ff.fish+fish/completions/ff.fish - 自动更新:日常
ff命令超过间隔(默认开、24h)会顺带git pull --ff-only origin main更新~/.dotfile,成功且有新提交后再 reload。配置在本机~/.config/ff/config(enabled、interval),时间戳~/.local/share/ff/state,不要进 git。跳过:FF_NO_AUTO_UPDATE=1或ff --no-auto-update …。显式ff update立即拉取并刷新时间戳,这次不再走自动更新。脏工作区、超时、网络失败时 stderr 一行并继续当前命令。回归:fish fish/tests/ff-auto-update.fish
Git 配置
- 公共配置在
git/.gitconfig - 身份:不设全局
user.name/user.email,user.useConfigOnly = true。未匹配目录时拒绝 commit,避免错用身份~/.dotfile/、~/code/、~/.pouch/→git/.gitconfig.personal(个人,进仓库,已写 name/email)~/workrepo/→~/.gitconfig.work(公司,仅本机;git-init会生成空模板)- include 目标文件必须存在,否则该目录下 git 命令会 fatal
- 凭据(所有 Git 版本):
git/git-credential.sh写在主配置里,使用!$HOME/.dotfile/...(Git 不展开~)- macOS:
osxkeychain→ 回退store(~/.git-credentials) - Linux:
libsecret→ 回退store
- macOS:
- 平台扩展(可选):
git/.gitconfig.darwin/.gitconfig.linux仅在高版本 Git 下通过 includeIf 加载 help.autocorrect:主配置为0(兼容旧 Git);Git ≥ 2.36 的平台文件里为prompt
边界(不要做的事)
- 不要把密钥、webhook、本机专用路径写进 git(
script/clash.sh等已在.gitignore) - 不要改
~/.config/fish/config.fish进仓库;本机差异放custom.fish - 不要把本机
mise use -g的工具写进mise/config.toml;写~/.config/mise/config.toml - 不要把
~/.config/ff/config或~/.local/share/ff/state写进 git(本机自动更新配置) - 不要为 init 复制整份配置到
$HOME;优先软链接到 dotfile - 脚本改动保持最小 diff,风格与相邻脚本一致(bash、
set -euo pipefail视情况) - 未经明确要求不要
git commit/git push
参考模板(新 bash 脚本)
#!/bin/bash
# 一行功能描述
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common/help.sh"
usage() {
cat <<'EOF'
用法: ...
选项:
-h, --help 显示此帮助
EOF
}
dotfile_help_requested "${1:-}" && dotfile_show_help
# ... 正文