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='' } # for color export CLICOLOR=1 # \h:\W \u\$ PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND" export PS1='\[\033[01;33m\]\u@\[\033[01;31m\]\W\[\033[00;31m\] $git_branch\[\033[01;31m\]\$\[\033[00m\] '