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

简介: #set git branch green=$'\e[1;32m' magenta=$'\e[1;35m' normal_colours=$'\e[m' function find_git_branch { local dir=.
#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),让其生效即可。

最终效果:

 

  

目录
相关文章
|
3月前
|
Linux 网络安全
CentOS7服务器SSH登陆时自动显示服务器基础信息
CentOS7服务器SSH登陆时自动显示服务器基础信息
42 0
|
2月前
|
安全 Shell 网络安全
【Git】TortoiseGit(小乌龟)配置SSH和使用
【Git】TortoiseGit(小乌龟)配置SSH和使用
152 0
|
1月前
|
存储 安全 网络安全
Git 安全远程访问:SSH 密钥对生成、添加和连接步骤解析
SSH(Secure Shell)是一种用于安全远程访问的协议,它提供了加密通信和身份验证机制。在使用 SSH 连接到远程 Git 存储库时,您可以使用 SSH 密钥对来确保安全性。以下是关于如何生成和使用 SSH 密钥对的详细步骤: 生成 SSH 密钥对
115 2
|
4月前
|
Linux 网络安全
|
4月前
|
开发工具 git
idea的Terminal终端操作git时, git log的注释乱码问题
最近工作比较清闲, 于是在自己的项目中测试: 假如git reset回滚到之前的版本, 后悔了. 应该如何回撤回回滚, 但是又被一些小问题拌住了...
63 0
|
4月前
|
监控 Linux 网络安全
百度搜索:蓝易云【CentOS7如何使用fail2ban防范SSH暴力破解攻击?】
请注意,fail2ban还有其他功能和配置选项可供使用,您可以进一步定制以满足您的需求。您可以查阅fail2ban的官方文档或其他资源以了解更多详细信息和配置选项。
37 1
|
23天前
|
存储 网络安全 开发工具
Git的GUI图形化工具&ssh协议&IDEA集成Git
Git的GUI图形化工具&ssh协议&IDEA集成Git
113 0
|
4月前
|
Shell 网络安全 开发工具
git02->gui图形化界面使用,ssh协议,idea集成GIT
git02->gui图形化界面使用,ssh协议,idea集成GIT
51 0
git02->gui图形化界面使用,ssh协议,idea集成GIT
|
4月前
|
安全 网络安全 开发工具
【Git】gui图形化界面的使用、ssh协议以及idea集成Git
【Git】gui图形化界面的使用、ssh协议以及idea集成Git
62 0
|
4月前
|
存储 网络安全 开发工具
百度搜索:蓝易云【Git多账号多仓库配置SSH?】
通过按照以上步骤配置SSH,您将能够在Git中使用多个账号和多个仓库,同时保持它们之间的独立性。请确保在配置和使用时注意使用正确的账号和仓库。
34 0

热门文章

最新文章