首页 » Linux » 正文

【转】centos ssh终端下高亮显示git分支名

发表于: PHP,JS,Golang,Shopify学习交流博客 – 咪啪咪啪的小木屋 · 2018-5-7 ·  1,500 views  ·  0 replies 

作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com

#set git branch
green=$'\e[1;32m'
magenta=$'\e[1;35m'
normal_colours=$'\e[m'

function 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=' (unknown)'
            fi
            return
        fi
        dir="../$dir"
    done
    git_branch=''
}

PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
PS1="\[$green\]\u@\h:\w\[$magenta\]\$git_branch\[$green\]\\[$normal_colours\] "

将上面这段,追加 /etc/profile 或 ~/.bash_profie 或 ~/.bashrc 任何一个的最后,然后source /etc/profile (或source ~/.bash_profile 或 source ~/.bashrc),让其生效即可。

«上一篇: :下一篇»

0 thoughts on “【转】centos ssh终端下高亮显示git分支名”

  1. 还没有任何评论,你来说两句吧

Leave a reply