Closed chiawenwang closed 6 months ago
完整如下:
function git_branch {
branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
if [ "${branch}" != "" ];then
if [ "${branch}" = "(no branch)" ];then
branch="(`git rev-parse --short HEAD`...)"
fi
echo " ($branch)"
fi
}
export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '
对于 Bash shell
export PS1='[\033[36m]\u@\h[\033[m]:[\033[32m]\w[\033[m]:[\033[31m]$(__git_ps1)[\033[m] '
保存文件并重新加载配置,使用命令:
source ~/.bashrc