fix: copy git config template on install

This commit is contained in:
2026-03-28 09:02:23 +08:00
parent d97c666ffc
commit 33ba81ba1b
5 changed files with 40 additions and 21 deletions

26
AGENTS.md Normal file
View File

@@ -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.

View File

@@ -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)

View File

@@ -245,7 +245,7 @@ antigen apply
### 修改 Git 配置
编辑 `~/.dotfiles/git/config` 或直接运行
仓库中的 `git/config` 只作为模板使用。机器上的实际配置请直接修改 `~/.gitconfig`
```bash
git config --global user.name "Your Name"

View File

@@ -176,7 +176,7 @@ figma # 设计
### Git 配置模板
`git/config` 使用占位符,首次使用时需要配置
`git/config` 是仓库内模板;`./setup.sh install` 会将它复制到 `~/.gitconfig`。首次使用后请在本机副本中填写真实信息
```bash
git config --file ~/.gitconfig user.name "Your Name"

View File

@@ -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"