zoukankan      html  css  js  c++  java
  • mac bash上显示git分支与状态

     

    主要实现

    • 显示当前路径
    • 显示当前所在分支
    • 显示当前修改状态
      • = 表示一个干净的分支
      • ~ 表示文件有改动
      • # 表示已commit 但未 push

     

    通过网上搜索和自己根据实际需要修改的代码如下:

    .bash_profile

    function parse_git_dirty {
        local git_status=$(git status 2> /dev/null | tail -n1) || $(git status 2> /dev/null | head -n 2 | tail -n1);
        local git_now;
        if [[ "$git_status" != "" ]]; then
            #local git_now; # 标示
    	#echo "${git_status}"
            if [[ "$git_status" =~ nothing to commit || "$git_status" =~  Your branch is up-to-date with ]]; then
                git_now="=";
            elif [[ "$git_status" =~ no changes added to commit ]]; then
                git_now='~';
           # elif [[ "$git_status" =~ Changes to be committed ]]; then #Changes to be committed
            #    git_now='*';
           # elif [[ "$git_status" =~ Untracked files ]]; then
            #    git_now="+";
           # elif [[ "$git_status" =~ Your branch is up-to-date with ]]; then
            #    git_now="#";
            fi
           # echo "${git_now}";
        elif [[ "$git_status" = "" ]]; then
    	git_now="#";
        fi
       echo "${git_now}"
    }
    
    
    function git_branch {
        ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
        echo "("${ref#refs/heads/}") ";
    }
    
    
    PS1="[[33[1;32m]w[33[0m]] [33[0m][33[1;36m]$(git_branch)[33[0;31m]$(parse_git_dirty)[33[0m]$ "
    

      

  • 相关阅读:
    vim 编辑器使用
    PHP高并发高负载系统架构(转载)
    类的使用
    linux下EC20 4G模块驱动移植
    linux 4G模块拨号脚本
    linux4.1.4上移植ME909s-821,MU609 4G模块驱动
    shell脚本语之运算符
    vim的列编辑操作
    linux下普通用户添加 sudo 免密码
    4G模块在AM335x上的移植
  • 原文地址:https://www.cnblogs.com/yiyi17/p/11044441.html
Copyright © 2011-2022 走看看