美文网首页
GIT显示分支

GIT显示分支

作者: J书越来越垃圾了 | 来源:发表于2017-03-22 09:01 被阅读42次

    linux 下 GIT显示分支 以及路径

    vi ~/.bashrc 记得soure(来源于网络)

    function git_branch {
        ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
        echo "("${ref#refs/heads/}") ";
    }
    
    function parse_git_dirty {
        local git_status=$(git status 2> /dev/null | tail -n1) || $(git status 2> /dev/null | head -n 2 | tail -n1);
        if [[ "$git_status" != "" ]]; then
            local git_now; # 标示
            if [[ "$git_status" =~ nothing\ to\ commit || "$git_status" =~  Your\ branch\ is\ up\-to\-date\ with ]]; then
                git_now="=";
            elif [[ "$git_status" =~ Changes\ not\ staged || "$git_status" =~ no\ changes\ added ]]; 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\ ahead ]]; then
                git_now="#";
            fi
            echo "${git_now}";
        fi
    }
    
    PS1="[\[\e[1;35m\]\u\[\e[1;32m\]@hostname:\w\[\e[0m\]] \[\e[0m\]\[\e[1;36m\]\$(git_branch)\[\033[0;31m\]\$(parse_git_dirty)\[\033[0m\]]\$"   
    

    相关文章

      网友评论

          本文标题:GIT显示分支

          本文链接:https://www.haomeiwen.com/subject/dugnnttx.html