zoukankan      html  css  js  c++  java
  • 如何在终端实时展现当前运行的git分支

    我们在终端操作git的时候,是可以实时的get到当前所在的分支的

    操作文件:

    ~/.bash_profile

    加入以下代码:

    ## 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=''
    }
    
    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="$white[$magentau$white@$greenh$white:$cyanw$yellow$git_branch$white]$ $normal"

    保存后重启shell即可

  • 相关阅读:
    web性能优化
    9.1_the end
    8.28_the end
    1.获取元素绝对位置
    8.14_end
    JavaScript 函数用途
    JavaScirpt事件处理
    《JavaScript语言精粹》读书笔记
    《图解http协议》之HTTPs学习笔记
    Laya 1.x 按文件夹TS代码合并
  • 原文地址:https://www.cnblogs.com/cuoreqzt/p/4612808.html
Copyright © 2011-2022 走看看