- 进入home目录
cd ~
- 编辑.bashrc文件
vi .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\] \$ '
- 保存
- 执行以下代码
source ./.bashrc
- 执行以下代码重启
echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
最终效果