| 導語 若是你是用命令行來使用Git的話,當在一個項目中頻繁使用多個分支時,能夠使用 git status 命令查詢本身如今正工做在哪一個分支下面,不過不免有腦子發昏的時候,忘記本身在哪一個分支下面,於是發生誤操做之類的杯具。 那麼把分支顯示在 Shell 提示符中無疑方便了不少,不再須要頻繁的使用 git status 命令了…git
廢話很少,直接上代碼,放到 ~/.bash_profile 或者 ~/.profile裏便可bash
## Parses out the branch name from .git/HEAD: find_git_branch () { local dir=. head until [ "$dir" -ef / ]; do if [ -f "$dir/.git/HEAD" ]; then head=$(< "$dir/.git/HEAD") if [[ $head = ref:\ refs/heads/* ]]; then git_branch=" → ${head#*/*/}" elif [[ $head != '' ]]; then git_branch=" → (detached)" else git_branch=" → (unknow)" fi return fi dir="../$dir" done git_branch='' } PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
# Hereespa
black=$'\[\e[1;30m\]'命令行
red=$'\[\e[1;31m\]'code
green=$'\[\e[1;32m\]'orm
yellow=$'\[\e[1;33m\]'blog
blue=$'\[\e[1;34m\]'it
magenta=$'\[\e[1;35m\]'class
cyan=$'\[\e[1;36m\]'file
white=$'\[\e[1;37m\]'
normal=$'\[\e[m\]'
PS1="$white[$magenta\u$white@$green\h$white:$cyan\w$yellow\$git_branch$white]\$ $normal"