logo
0
0
WeChat Login
docs: 更新 README 文档

ohmybash

Bash Git 提示符和补全脚本,提供类似 posh-git 的 Git 状态显示。

文件说明

文件说明
git-prompt.bashGit 状态提示符脚本,在 Bash 中显示详细的 Git 状态信息
git-completion.bashGit 命令补全脚本,提供分支名、远程名等自动补全

安装

方法 1:使用 curl 下载

# 下载 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

方法 2:使用 wget 下载

# 下载 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

方法 3:克隆仓库

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] $

致谢