【发布时间】:2020-12-16 18:43:32
【问题描述】:
我正在尝试将我当前的 git 分支添加到我的 bash 终端提示符中。我已将此文件:https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh 复制到我的主目录,这是 .bashrc 中与我的提示相关的部分:
source ~/.git-prompt.sh
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00;31m\] \W$(__git_ps1 " (%s)")\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\ \W$(__git_ps1 " (%s)")$ '
fi
但是,\W$(__git_ps1 " (%s)") 正在返回当前文件夹和分支,并在不在存储库中时返回当前目录。
是否可以让它只在存储库中显示当前分支,而当我不在一个存储库中时,什么都不显示?
【问题讨论】:
-
鼓励您朝着正确的方向前进:您的问题已被很好地张贴、记录等,但不幸的是,它是重复的。