centos切换目录的时候,如果切换到git分支的目录,就显示git branch的名称。
可以这样操作
cd ~
vim .bashrc
在文件中加入以下代码
if [ -f /etc/bashrc ]; then. /etc/bashrc
fi
black=$'\[\e[1;30m\]'red=$'\[\e[1;31m\]'green=$'\[\e[1;32m\]'yellow=$'\[\e[1;33m\]'blue=$'\[\e[1;34m\]'magenta=$'\[\e[1;35m\]'cyan=$'\[\e[1;36m\]'white=$'\[\e[1;37m\]'normal=$'\[\e[m\]'USER="root" #自定义
function precmd {cd $1GITBRANCH=`sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'`PS1="$white[$magenta\u$white@$green$USER$white:$cyan\w$yellow$GITBRANCH$white]\$ $normal"
}
alias cd=precmd
这样新打开终端的时候就起作用了