【发布时间】:2017-05-29 02:57:50
【问题描述】:
我想在终端上的 git repo 中显示我当前的分支状态(如 * 表示已修改),如下所示。但是,即使我切换到 git repo,它也总是显示以下内容。
ᴾᴋᴹɴ iFeelNewsBot master wrong... ↪
当我在终端中打开一个新选项卡时,它会显示当前 git 分支的正确文本渲染,可以进一步查看。它应该是什么样子
ᴾᴋᴹɴ iFeelNewsBot master * ↪
我的自定义 bash 配置文件代码如下
# user name and color
USER_NAME='mr.universe';
TRAINER_TITLE='ᴾᴋᴹɴ'
USER_NAME_COLOR='\[\033[00m\]';
END_COLOR='\e[0m';
# \W = current working path
# \u = user
function parse_git_dirty {
gitStatus=$(git status 2> /dev/null | tail -n1)
clean="nothing to commit, working directory clean"
if [[ -d "./.git" ]]
then
[[ $gitStatus != $clean ]] && echo "*" || echo "="
elif [[ ! -d "./.git" ]]
then
echo "wrong...."
else
echo "STOP"
fi
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1="\[\033[40;02m\]$TRAINER_TITLE \W \[\033[36;02m\]\[\033[29;00m\]\$(git branch 2>/dev/null | grep '^*' | colrm 1 2) $(parse_git_dirty) ↪ "
【问题讨论】:
-
看起来
parse_git_branch函数从未使用过。