首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >centos ssh终端下高亮显示git分支名

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

作者头像
菩提树下的杨过
发布2018-01-18 16:50:24
1.2K0
发布2018-01-18 16:50:24
举报
#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),让其生效即可。

最终效果:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-02-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档