cd ~
复制代码
.bashrc
文件(如没有此文件会自动建立)vim .bashrc
复制代码
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\] \$ '
复制代码
先按git
esc
复制代码
接着shell
:wq
复制代码
source ./.bashrc
复制代码
Mac 下面启动的 shell 是 login shell,因此加载的配置文件是
.bash_profile
,不会加载.bashrc
。若是是 Mac 的话,须要再执行下面的命令,这样每次开机后才会自动生效:vim
echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
复制代码