zoukankan      html  css  js  c++  java
  • Shell颜色及显示git分支配置

    # Ubuntu终端下命令行颜色配置
    ## Parses out the branch name from .git/HEAD:
    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="[→ (unknow)]"
    fi
    return
    fi
    dir="../$dir"
    done
    git_branch=''
    }
     
    # git目录显示当前分支
     
    PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
    # Here is bash color codes you can use
    black=$'[e[1;30m]'
    red=$'[e[1;31m]'
    green=$'[e[1;32m]'
    yellow=$'[e[1;33m]'
    blue=$'[e[1;34m]'
    magenta=$'[e[1;35m]'
    cyan=$'[e[1;36m]'
    white=$'[e[1;37m]'
    normal=$'[e[m]'
    PS1="$magentau$white@$greenh$white:$cyanw$yellow$git_branch$white$red$ $normal"
     
     
    用法:把上述代码追加到~/.bashrc文件后面,source ~/.bashrc后打开新终端就可以看到效果了
  • 相关阅读:
    1860 最大数
    1164 统计数字
    1063 合并果子
    1098 均分纸牌
    2806 红与黑
    1168 火柴棒等式
    1910 递归函数
    2774 火烧赤壁
    2017.0705.《计算机组成原理》-存储器
    2017.0704.《计算机组成原理》-动态RAM
  • 原文地址:https://www.cnblogs.com/fuleying/p/5331200.html
Copyright © 2011-2022 走看看