feat: add install-my-git-bash skill (my-git-bash/SKILL.md)
This commit is contained in:
commit
dbac52cc17
2 changed files with 195 additions and 0 deletions
188
my-git-bash/SKILL.md
Normal file
188
my-git-bash/SKILL.md
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
---
|
||||
name: install-my-git-bash
|
||||
description: "在 Windows Git Bash 上安装 xnng/my-git-bash 终端美化与工具集(mintty 主题、git 提示符、tmux、tree、Powerline 字体、alias)。当用户说装机、新机器初始化 Git Bash、安装/配置 my-git-bash、恢复终端配置、美化 Git Bash、装 tmux/tree/Powerline 字体时使用。严格按既定偏好执行:绝不整体覆盖 .bash_profile/.gitconfig 而是增量合并、unicode 箭头 ➜ 改 ASCII ->、备份后再覆盖系统文件、检测并跳过已装工具。"
|
||||
---
|
||||
|
||||
# 安装 my-git-bash(Git Bash 美化与工具集)
|
||||
|
||||
把 `https://github.com/xnng/my-git-bash` 这套 Git Bash 配置装到本机:mintty 主题、git 提示符、tmux、tree、Powerline 字体、alias。**重点是按用户偏好安全地安装,绝不破坏用户已有的个人配置。**
|
||||
|
||||
## ⚠️ 核心原则(必须遵守,不可省略)
|
||||
|
||||
这五条是用户明确要求的工作方式,违反任何一条都算事故:
|
||||
|
||||
1. **永不整体覆盖用户的 dotfiles。** 禁止 `cp .bash_profile ~`、`cp .gitconfig ~` 这类整文件覆盖。`.bash_profile` 要**增量追加**(带日期标记段落,可整段删除);`.gitconfig` **完全不碰**(里面有用户真实提交身份和代理,覆盖会让 commit 变成别人、还可能注入无效代理)。
|
||||
2. **unicode 符号改 ASCII。** 仓库 `git-prompt.sh` 的提示符箭头 `➜`(U+279C)在 GBK 终端会乱码/报错,必须改成 `->`。同理避免 `→ │ ╔ ▶` 等。
|
||||
3. **覆盖系统文件前先备份。** `/etc/profile.d/git-prompt.sh` 等系统文件被覆盖前,先 `cp` 一份 `.bak`。
|
||||
4. **检测后跳过已装工具。** 装前先 `command -v` 检测;wget 系统通常自带 → 跳过 `tools/wget.exe`,不要覆盖。
|
||||
5. **增量改动加可识别标记。** 追加内容用 `# --- 以下增量来自 my-git-bash (YYYY-MM-DD) ---` … `# --- end my-git-bash ---` 包裹,方便日后识别/删除。
|
||||
|
||||
关联记忆:`feedback-dotfiles-incremental-encoding`、`user-iflytek-embedded-dev`。
|
||||
|
||||
## 第 0 步:预检(先跑,结果决定后续)
|
||||
|
||||
```bash
|
||||
whoami # 确认身份
|
||||
touch /usr/bin/.wt 2>/dev/null && echo "管理员OK" && rm -f /usr/bin/.wt || echo "非管理员:系统目录操作需重开管理员 Git Bash"
|
||||
for t in tmux wget tree winpty code git; do printf "%-8s " $t; command -v $t || echo 未装; done
|
||||
git --version
|
||||
```
|
||||
|
||||
同时**必须读**用户现有配置,判断冲突:
|
||||
|
||||
- `cat ~/.bash_profile 2>/dev/null` —— 看已有哪些 alias/函数(尤其 git 快捷键、`tree`、GBK 转码等),增量时跳过已有的。
|
||||
- `cat ~/.gitconfig 2>/dev/null` —— 确认用户身份,**只读不改**。
|
||||
- `ls ~/.minttyrc ~/.tmux.conf 2>/dev/null` —— 不存在才能直接装。
|
||||
|
||||
## 第 1 步:克隆仓库
|
||||
|
||||
```bash
|
||||
git clone https://github.com/xnng/my-git-bash # 国内不畅可换 gitee: https://gitee.com/xnng/bash.git
|
||||
cd my-git-bash
|
||||
```
|
||||
|
||||
## 第 2 步:备份系统 git-prompt.sh
|
||||
|
||||
```bash
|
||||
cp /etc/profile.d/git-prompt.sh /etc/profile.d/git-prompt.sh.bak
|
||||
```
|
||||
|
||||
## 第 3 步:安装 Powerline 字体(管理员)
|
||||
|
||||
```bash
|
||||
cp "fonts/DejaVu Sans Mono for Powerline.ttf" /c/Windows/Fonts/
|
||||
MSYS_NO_PATHCONV=1 reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" \
|
||||
/v "DejaVu Sans Mono for Powerline (TrueType)" /t REG_SZ \
|
||||
/d "DejaVu Sans Mono for Powerline.ttf" /f
|
||||
```
|
||||
|
||||
- `MSYS_NO_PATHCONV=1` 必加,否则 `/v /t /d /f` 被 MSYS 当路径转换而失败。
|
||||
- `reg` 成功输出中文(GBK)在终端会显示乱码,**属正常**,看退出码即可。
|
||||
- 回退(非管理员或失败):`start c://Windows//Fonts && start fonts`,手动拖拽安装。
|
||||
|
||||
## 第 4 步:主题(.minttyrc + 改箭头的 git-prompt.sh)
|
||||
|
||||
先把 `git-prompt.sh` 第 15 行的 `'➜ '` 改成 `'-> '`(用 Edit 工具最稳;用 sed 注意分隔符**不能**用 `~` 或 `/`,因为内容里有 `~`/`/`):
|
||||
|
||||
```bash
|
||||
cp .minttyrc ~ # 不存在才直接 cp;已存在则先备份再覆盖
|
||||
cp git-prompt.sh /etc/profile.d/git-prompt.sh
|
||||
```
|
||||
|
||||
## 第 5 步:tmux 本体 + 配置
|
||||
|
||||
```bash
|
||||
cp tmux/bin/* /usr/bin
|
||||
cp tmux/share/* /usr/share -r
|
||||
cp tmux/.tmux.conf ~ # 仓库完整配置(prefix=C-a、分屏 |-、vi 模式、状态栏),优于 README 的 echo
|
||||
```
|
||||
|
||||
## 第 6 步:tmux 持久化插件(可选,问用户)
|
||||
|
||||
插件能保存/恢复 session,但会拖慢 tmux 启动;用户不要就跳过。
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.tmux/plugins/tpm
|
||||
git clone --depth 1 https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm # 可能因网络失败,失败不影响 tmux 本体
|
||||
# 国内备选: git clone https://gitclone.com/github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
|
||||
```
|
||||
|
||||
clone 成功后,取消 `~/.tmux.conf` 中插件行的注释(5 个 `@plugin` + 1 个 `run`)。sed 用 `:` 作分隔符(避开内容里的 `~` 和 `/`):
|
||||
|
||||
```bash
|
||||
sed -i -E "s:^# (set -g @plugin|run '):\1:" ~/.tmux.conf
|
||||
grep -nE "@plugin|tpm/tpm" ~/.tmux.conf # 验证已无 # 前缀
|
||||
```
|
||||
|
||||
装完告诉用户:进 tmux 后按 **`Ctrl+a` 再按大写 `I`** 让 tpm 拉取 resurrect/continuum(prefix 是 C-a,不是默认 C-b)。
|
||||
|
||||
## 第 7 步:tree(跳过 wget)
|
||||
|
||||
```bash
|
||||
cp tools/tree.exe /usr/bin # 只拷 tree;wget 系统已自带,不覆盖
|
||||
```
|
||||
|
||||
## 第 8 步:alias 增量合并(核心:分析后追加,不是覆盖)
|
||||
|
||||
**先读用户 `~/.bash_profile`,按下表分类**,只追加「用户没有、不冲突、无 bug」的:
|
||||
|
||||
| 类别 | 处理 | 仓库示例 |
|
||||
|---|---|---|
|
||||
| 用户已有 | **跳过** | `gs`/`gclean`/`sysoff`/`sysre`、用户的 `tree='tree --charset ASCII'`(比仓库好,避免乱码)、用户的 GBK 转码 `zw`/`git_diff_gbk` |
|
||||
| 有冲突 | **跳过** | `.='cd ~'`(破坏 `.` 语义)、`tree1`/`tree2`(与用户 ASCII tree 冲突) |
|
||||
| 有 bug | **跳过** | `utf8`/`gbk`(`sed -i 's/GBK/UTF-8/'` 单引号嵌套错误,且用户已有自己的方案) |
|
||||
| 有用且用户没有 | **追加** | git 快捷键 `ga/gc/gp/gl/gb/gch/gm`、导航 `.. / ... / ,`、`e`/`cls`、tmux `tn`/`ta`、`bashalias`/`gitconfig`(用 `code` 打开配置)、`ep`/`c` |
|
||||
|
||||
追加用 heredoc(`'EOF'` 带引号防展开),**带防重复检查 + 日期标记**:
|
||||
|
||||
```bash
|
||||
if grep -q "my-git-bash 仓库 ($(date +%F) 添加)" ~/.bash_profile 2>/dev/null; then
|
||||
echo "已追加过,跳过"
|
||||
else
|
||||
cat >> ~/.bash_profile << 'MYGITBASH_EOF'
|
||||
|
||||
# --- 以下增量来自 my-git-bash 仓库 (YYYY-MM-DD 添加) ---
|
||||
# git 快捷键
|
||||
alias ga='git add .'
|
||||
alias gc='git commit -m'
|
||||
alias gp='git push'
|
||||
alias gl='git pull'
|
||||
alias gb='git branch'
|
||||
alias gch='git checkout'
|
||||
alias gm='git merge'
|
||||
# 目录导航
|
||||
alias ..='cd ..'
|
||||
alias ...='cd ../..'
|
||||
alias ,='cd -'
|
||||
alias e='exit'
|
||||
alias cls='clear'
|
||||
# tmux
|
||||
alias tn='tmux new -s m'
|
||||
alias ta='tmux a'
|
||||
# 用 VS Code 快速打开配置
|
||||
alias bashalias='code ~/.bash_profile'
|
||||
alias gitconfig='code ~/.gitconfig'
|
||||
# 资源管理器/VSCode 打开当前目录
|
||||
alias ep='start . && exit'
|
||||
alias c='code . && exit'
|
||||
# --- end my-git-bash ---
|
||||
MYGITBASH_EOF
|
||||
fi
|
||||
```
|
||||
|
||||
> 上面的 `YYYY-MM-DD` 换成当天日期;清单按用户实际已有情况增删——**分析是这步的灵魂,不要无脑全加**。
|
||||
|
||||
## ❌ 绝不做
|
||||
|
||||
- `cp .bash_profile ~`(覆盖工作配置)
|
||||
- `cp .gitconfig ~`(覆盖提交身份 + 注入代理)
|
||||
- `cp tools/wget.exe /usr/bin`(覆盖系统 wget)
|
||||
|
||||
## 验证
|
||||
|
||||
```bash
|
||||
# 箭头已是 ASCII(cat -A 应显示 '-> ',无 M-b/M-f 的 UTF-8 字节)
|
||||
grep -n "PS1=\"\$PS1\"'" /etc/profile.d/git-prompt.sh | cat -A
|
||||
tmux -V && tree --version | head -1
|
||||
source ~/.bash_profile && type ga gp gch tn .. # alias 可加载
|
||||
grep -q "end my-git-bash" ~/.bash_profile && echo "alias 段已追加"
|
||||
grep -m1 email ~/.gitconfig # 身份未被改动
|
||||
```
|
||||
|
||||
最后提醒用户:**重启 Git Bash** 才能让主题/字体/提示符/新 alias 生效。
|
||||
|
||||
## 回退
|
||||
|
||||
- 提示符:`cp /etc/profile.d/git-prompt.sh.bak /etc/profile.d/git-prompt.sh`
|
||||
- alias:编辑 `~/.bash_profile`,删两个 `# ---` 之间的段落
|
||||
- tmux:`rm /usr/bin/tmux.exe`
|
||||
- 字体:控制面板 → 字体 → 删除 `DejaVu Sans Mono for Powerline`
|
||||
|
||||
## 平台/编码备忘
|
||||
|
||||
- 调 Windows 原生命令(`reg`、`shutdown` 等)加 `MSYS_NO_PATHCONV=1`,防 `/x` 参数被路径转换。
|
||||
- 中文/GBK 程序输出在 UTF-8 终端会乱码,看退出码而非输出文字判断成败。
|
||||
- sed 分隔符选内容里不出现的字符(这里用 `:`),别用 `~`/`/`。
|
||||
- 仓库已 cloned 到 `D:\iflytekCode\my-git-bash`(2026-07-24 首装);新机器重装时重新 clone 即可,勿依赖旧路径。
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue