From 33ba81ba1ba241277ee586f00afd391f06b15f53 Mon Sep 17 00:00:00 2001 From: d0zingcat Date: Sat, 28 Mar 2026 09:02:23 +0800 Subject: [PATCH] fix: copy git config template on install --- AGENTS.md | 26 ++++++++++++++++++++++++++ CHECKLIST.md | 2 +- MIGRATION_GUIDE.md | 2 +- README.md | 2 +- setup.sh | 29 +++++++++++------------------ 5 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..0306e51 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,26 @@ +# Repository Guidelines + +## Project Structure & Module Organization +This repository manages macOS dotfiles and bootstrap scripts. Root-level files such as [setup.sh](/Users/d0zingcat/.dotfiles/setup.sh), [Brewfile](/Users/d0zingcat/.dotfiles/Brewfile), [README.md](/Users/d0zingcat/.dotfiles/README.md), and [QUICKSTART.md](/Users/d0zingcat/.dotfiles/QUICKSTART.md) drive installation and recovery. App-specific config lives in `nvim/`, `wezterm/`, `alacritty/`, `ghostty/`, `git/`, `direnv/`, `ssh/`, and `tmux/`. Neovim code is organized under `nvim/lua/config` for core behavior and `nvim/lua/plugins` for plugin specs. `tmux/plugins/tpm` is a Git submodule; treat it as vendored code unless you are intentionally updating TPM. + +## Build, Test, and Development Commands +Use the setup script instead of ad hoc symlink changes: + +- `./setup.sh install`: link managed files into `$HOME` and `$HOME/.config`. +- `./setup.sh check`: verify expected tools, links, and directories. +- `./setup.sh full-recover`: bootstrap a new machine end to end. +- `./setup.sh backup`: refresh tracked backup artifacts such as `Brewfile`. +- `brew bundle install`: install CLI tools and apps from [Brewfile](/Users/d0zingcat/.dotfiles/Brewfile). +- `tmux/plugins/tpm/tests/test_plugin_installation.sh`: example TPM plugin test entrypoint when working inside the submodule. + +## Coding Style & Naming Conventions +Shell code is written for `zsh`; keep functions small, prefer descriptive names like `cmd_install`, and follow the existing 4-space indentation in [setup.sh](/Users/d0zingcat/.dotfiles/setup.sh). Lua plugin files in `nvim/lua/plugins` use lowercase filenames grouped by concern, for example `python.lua` and `lspconfig.lua`. Keep new config directories lowercase and mirror their target app name. For Python-style checks, [pycodestyle](/Users/d0zingcat/.dotfiles/pycodestyle) ignores `E501`. Neovim tooling references `stylua`, `luacheck`, and `shellcheck`; use them when available before submitting changes. + +## Testing Guidelines +There is no top-level test suite for the dotfiles themselves, so validate changes with `./setup.sh check` and, when relevant, a dry run on a disposable shell session. Automated tests currently live under `tmux/plugins/tpm/tests`; keep test scripts executable and named `test_*.sh`. + +## Commit & Pull Request Guidelines +Recent history favors short imperative subjects, often Conventional Commit style: `feat: add deps`, `refactor(nvim): simplify fold config`, `docs: 更新备份相关文档说明`. Prefer `type: summary` for new work and keep subjects under roughly 72 characters. PRs should describe user-visible config changes, list any manual setup steps, link related issues, and include screenshots only for terminal or editor UI changes. + +## Security & Configuration Tips +Do not commit secrets from `~/.ssh`, `~/.kube`, `.1password`, or local backup outputs. Treat `git/config` and `ssh/example` as templates only: `./setup.sh install` should copy them into place for local editing rather than symlinking machine-specific values back into the repository. diff --git a/CHECKLIST.md b/CHECKLIST.md index 015b1cd..40779f2 100644 --- a/CHECKLIST.md +++ b/CHECKLIST.md @@ -38,7 +38,7 @@ - [ ] **自动** ~/.config/tmux 软链接 - [ ] **自动** ~/.config/wezterm 软链接 - [ ] **自动** ~/.config/starship.toml 软链接 -- [ ] **自动** ~/.gitconfig 软链接 +- [ ] **自动** 用 `git/config` 模板覆盖生成 ~/.gitconfig - [ ] **自动** 如不存在则用 `ssh/example` 初始化 ~/.ssh/config - [ ] **自动** 如可用则创建 ~/.1password/agent.sock 符号链接 - [ ] **自动** Git 全局配置 (excludesfile, defaultBranch) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index ba927ea..85eac0b 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -245,7 +245,7 @@ antigen apply ### 修改 Git 配置 -编辑 `~/.dotfiles/git/config` 或直接运行: +仓库中的 `git/config` 只作为模板使用。机器上的实际配置请直接修改 `~/.gitconfig`: ```bash git config --global user.name "Your Name" diff --git a/README.md b/README.md index cf214d4..f9b718c 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ figma # 设计 ### Git 配置模板 -`git/config` 使用占位符,首次使用时需要配置: +`git/config` 是仓库内模板;`./setup.sh install` 会将它复制到 `~/.gitconfig`。首次使用后请在本机副本中填写真实信息: ```bash git config --file ~/.gitconfig user.name "Your Name" diff --git a/setup.sh b/setup.sh index 6592391..4c88e8b 100755 --- a/setup.sh +++ b/setup.sh @@ -46,11 +46,6 @@ CONFIG_FILES=( ghostty ) -# Custom file mappings (from -> to) -CUSTOM_FILES=( - "git/config .gitconfig" -) - # Rustup components RUSTUP_COMPONENTS=( clippy @@ -238,20 +233,18 @@ function cmd_install() { fi done - # Link custom files - print_warning "Linking custom files..." - for row in "${CUSTOM_FILES[@]}"; do - IFS=' ' read -r from to <<< "$row" - if [ -f "$WORKING_DIR/$from" ]; then - # Create parent directory if needed - local to_dir=$(dirname "$HOME_DIR/$to") - mkdir -p "$to_dir" - ln -svfn "$WORKING_DIR/$from" "$HOME_DIR/$to" - print_success "Linked: $to" - else - print_warning "Not found: $from" + # Install git config from template by copying it into place. + local git_config_template="$WORKING_DIR/git/config" + local git_config_target="$HOME_DIR/.gitconfig" + if [ -f "$git_config_template" ]; then + if [ -L "$git_config_target" ]; then + rm "$git_config_target" fi - done + cp -f "$git_config_template" "$git_config_target" + print_success "Copied git config template to ~/.gitconfig" + else + print_warning "Not found: git/config" + fi # Install SSH config from template without symlinking it into the repo. local ssh_template="$WORKING_DIR/ssh/example"