美文网首页
Mac git分支颜色 显示

Mac git分支颜色 显示

作者: 点一下我的id | 来源:发表于2019-01-22 22:50 被阅读0次

    Step 1

    sudo vim ~/.bash_profile
    

    Step 2

    #display git branch in PS1
    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"
    
    black=$'\[\e[1;30m\]'
    red=$'\[\e[1;31m\]'
    green=$'\[\e[1;32m\]'
    yellow=$'\[\e[1;33m\]'
    blue=$'\[\e[1;34m\]'
    magenta=$'\[\e[1;35m\]'
    cyan=$'\[\e[1;36m\]'
    white=$'\[\e[1;37m\]'
    normal=$'\[\e[m\]'
    
    PS1="$green\u$white@$green\h:$cyan\w$yellow\$git_branch$normal\$ "
    

    Step 3

    source ~/.bash_profile
    

    相关文章

      网友评论

          本文标题:Mac git分支颜色 显示

          本文链接:https://www.haomeiwen.com/subject/nfldjqtx.html