Bash Git 提示符和补全脚本,提供类似 posh-git 的 Git 状态显示。
| 文件 | 说明 |
|---|---|
git-prompt.bash | Git 状态提示符脚本,在 Bash 中显示详细的 Git 状态信息 |
git-completion.bash | Git 命令补全脚本,提供分支名、远程名等自动补全 |
# 下载 git-prompt.bash
curl -o ~/.git-prompt.bash https://cnb.cool/sumu.k/ohmybash/-/git/raw/main/git-prompt.bash
# 下载 git-completion.bash
curl -o ~/.git-completion.bash https://cnb.cool/sumu.k/ohmybash/-/git/raw/main/git-completion.bash
# 下载 git-prompt.bash
wget -O ~/.git-prompt.bash https://cnb.cool/sumu.k/ohmybash/-/git/raw/main/git-prompt.bash
# 下载 git-completion.bash
wget -O ~/.git-completion.bash https://cnb.cool/sumu.k/ohmybash/-/git/raw/main/git-completion.bash
git clone https://github.com/username/ohmybash.git ~/.ohmybash
在 ~/.bashrc 中添加以下内容:
# 加载 Git 补全
source ~/.git-completion.bash
# 加载 Git 提示符
source ~/.git-prompt.bash
# 启用 Git 提示符
set_git_ps1
在 source ~/.git-prompt.bash 之前设置以下变量:
# 分支状态显示模式: Full / Compact / Minimal
GIT_PROMPT_BRANCH_DISPLAY="Full"
# 显示远程分支信息 (1=显示, 0=不显示)
GIT_PROMPT_SHOW_UPSTREAM=1
# 显示 stash 数量 (1=显示, 0=不显示)
GIT_PROMPT_SHOW_STASH=1
# 显示时间 (1=显示, 0=不显示)
GIT_PROMPT_SHOW_TIME=1
✓ user@host:~/project [main ≡ +0 ~0 -0 | +0 ~0 -0] $ ✓ user@host:~/project [feature ↑3 +1 ~2 -0 | +0 ~1 -0 !] $ ✗ user@host:~/project [bugfix ↓2 +0 ~0 -0 | +0 ~0 -0] $
git-completion.bash