终端中显示当前分支名称
效果截图

实现代码
在~/.bash_profile
的最后添加下面代码
######################################
# Git
######################################
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自动补全
$brew install bash-completion
添加代码
在~/.bash_profile
中加入
######################################
# auto completion
######################################
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi