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

    ssh终端显示git分支名:

     1 #set git branch
     2 green=$'e[0;32m'
     3 magenta=$'e[0;36m'
     4 normal_colours=$'e[m'
     5 
     6 function find_git_branch {
     7     local dir=. head
     8     until [ "$dir" -ef / ]; do
     9         if [ -f "$dir/.git/HEAD" ]; then
    10             head=$(< "$dir/.git/HEAD")
    11             if [[ $head == ref: refs/heads/* ]]; then
    12                 git_branch="(${head#*/*/})#"
    13             elif [[ $head != '' ]]; then
    14                 git_branch='(detached)'
    15             else
    16                 git_branch='(unknown)'
    17             fi
    18             return
    19         fi
    20         dir="../$dir"
    21     done
    22     git_branch='#'
    23 }
    24 
    25 PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
    26 PS1="[$green][u@h W][$magenta]$git_branch[$green]\[$normal_colours] "

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

    最终效果:

  • 相关阅读:
    hdu 4525(数学)
    hdu 4524(模拟)
    hdu 4523(大整数)
    hdu 4517(递推枚举统计)
    hdu 4520
    hdu 4519(数学题)
    hdu 4514(树的直径+并查集)
    hdu 4510(模拟)
    hdu 2089(数位DP)
    hdu 4506(数学,循环节+快速幂)
  • 原文地址:https://www.cnblogs.com/zzming/p/14079305.html
Copyright © 2011-2022 走看看