繁体   English   中英

Git 分支名称不会显示在 Mac 终端上

[英]Git Branch name won't show up on Mac Terminal

我在 Mac 的~/.bash_profile中添加了以下几行:

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

#Variables
userName="\u"
fullPath="\w"
systemName="\h"

#'$(tput setaf 14)' allows coloring for the prompt
#that immediately follows it. 14 is the color aqua.
#A list of colors can be accessed below:
#https://jonasjacek.github.io/colors/

#`$(tput sgr0)` stops the text coloring from continuing on.

#Personalized Terminal
PS1="\[$(tput setaf 118)\]${userName}\[$(tput setaf 3)\]@${systemName}\[$(tput setaf 14)\]${fullPath}\[$(tput setaf 222)\]\[$(parse_git_branch)\]\[$(tput setaf 160)\]$ \[$(tput sgr0)\]"
export PS1;

#export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

#------- Aliases -------

#Open Sublime Text Editor
alias subl="open -a /Applications/Sublime\ Text.app"
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

终端样式看起来不错,但我的parse_git_branch没有显示我的 git 分支的名称。 我在定义PS1值时搞砸了,但我不确定我做错了什么。

你可以试试这个:

PROMPT_COMMAND=$(cat << 'EOF'
git_prompt=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/')
EOF
)

#Variables
userName="\u"
fullPath="\w"
systemName="\h"

PS1="\[$(tput setaf 118)\]${userName}\[$(tput setaf 3)\]@${systemName}\[$(tput setaf 14)\]${fullPath}\[$(tput setaf 222)\]\[\$git_prompt\]\[$(tput setaf 160)\]$ \[$(tput sgr0)\]"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM