Terminal git 显示当前分支

增加到 /etc/brashrc
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"
PS1="\u@\h:\w\$git_branch\$ "

你可能感兴趣的:(开发管理工具)