zoukankan      html  css  js  c++  java
  • centos ssh终端下高亮显示git分支名

    #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),让其生效即可。

    最终效果:

      

  • 相关阅读:
    命令基础
    绑定在表单验证上的应用
    绑定和绑定的各种使用场景
    双向数据绑定
    事件
    委托应用及泛型委托和多播委托
    委托
    LINQ
    反射重要属性方法
    反射基本内容
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/highlight-syntax-color-display-git-branch-name.html
Copyright © 2011-2022 走看看