我想在下面的終端上通過git repo顯示當前分支狀態(如*表示已修改)。但是,即使切換到git repo,它總是顯示以下內容。在Mac終端上顯示git狀態不能用於自定義bash配置文件
ᴾᴋᴹɴ 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'函數從未被使用。 – ThomasW