Skip to content

Instantly share code, notes, and snippets.

@shishi
Forked from uasi/gist:214109
Created April 20, 2012 06:19

Revisions

  1. @uasi uasi revised this gist Apr 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ setopt re_match_pcre

    function rprompt-git-current-branch {
    local name st color gitdir action
    if [[ "$PWD" =~ '/¥.git(/.*)?$' ]]; then
    if [[ "$PWD" =~ '/\.git(/.*)?$' ]]; then
    return
    fi
    name=`git rev-parse --abbrev-ref=loose HEAD 2> /dev/null`
  2. @uasi uasi revised this gist Apr 12, 2012. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@

    autoload -Uz VCS_INFO_get_data_git; VCS_INFO_get_data_git 2> /dev/null

    setopt prompt_subst
    setopt re_match_pcre

    function rprompt-git-current-branch {
    local name st color gitdir action
    if [[ "$PWD" =~ '/¥.git(/.*)?$' ]]; then
    @@ -18,19 +21,18 @@ function rprompt-git-current-branch {
    action=`VCS_INFO_git_getaction "$gitdir"` && action="($action)"

    st=`git status 2> /dev/null`
    if [[ -n `echo "$st" | grep "^nothing to"` ]]; then
    if [[ "$st" =~ "(?m)^nothing to" ]]; then
    color=%F{green}
    elif [[ -n `echo "$st" | grep "^nothing added"` ]]; then
    elif [[ "$st" =~ "(?m)^nothing added" ]]; then
    color=%F{yellow}
    elif [[ -n `echo "$st" | grep "^# Untracked"` ]]; then
    elif [[ "$st" =~ "(?m)^# Untracked" ]]; then
    color=%B%F{red}
    else
    color=%F{red}
    fi


    echo "$color$name$action%f%b "
    }

    setopt prompt_subst

    RPROMPT='[`rprompt-git-current-branch`%~]'
  3. @uasi uasi revised this gist Apr 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ function rprompt-git-current-branch {
    if [[ "$PWD" =~ '/¥.git(/.*)?$' ]]; then
    return
    fi
    name=$(basename "`git symbolic-ref HEAD 2> /dev/null`")
    name=`git rev-parse --abbrev-ref=loose HEAD 2> /dev/null`
    if [[ -z $name ]]; then
    return
    fi
  4. @uasi uasi revised this gist Dec 28, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ function rprompt-git-current-branch {
    if [[ "$PWD" =~ '/¥.git(/.*)?$' ]]; then
    return
    fi
    name=`git branch 2> /dev/null | grep '^¥*' | cut -b 3-`
    name=$(basename "`git symbolic-ref HEAD 2> /dev/null`")
    if [[ -z $name ]]; then
    return
    fi
  5. @uasi uasi revised this gist Oct 25, 2009. 1 changed file with 15 additions and 12 deletions.
    27 changes: 15 additions & 12 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -2,30 +2,33 @@
    # Show branch name in Zsh's right prompt
    #

    autoload -U colors; colors
    autoload -Uz VCS_INFO_get_data_git; VCS_INFO_get_data_git 2> /dev/null

    function rprompt-git-current-branch {
    local name st color
    if [[ "$PWD" =~ '/\.git(/.*)?$' ]]; then
    local name st color gitdir action
    if [[ "$PWD" =~ '/¥.git(/.*)?$' ]]; then
    return
    fi
    name=`git branch 2> /dev/null | grep '^¥*' | cut -b 3-`
    if [[ -z $name ]]; then
    return
    fi
    st=`git status`

    gitdir=`git rev-parse --git-dir 2> /dev/null`
    action=`VCS_INFO_git_getaction "$gitdir"` && action="($action)"

    st=`git status 2> /dev/null`
    if [[ -n `echo "$st" | grep "^nothing to"` ]]; then
    color=${fg[green]}
    color=%F{green}
    elif [[ -n `echo "$st" | grep "^nothing added"` ]]; then
    color=${fg[yellow]}
    color=%F{yellow}
    elif [[ -n `echo "$st" | grep "^# Untracked"` ]]; then
    color=${fg_bold[red]}
    color=%B%F{red}
    else
    color=${fg[red]}
    fi


    echo "%{$color%}$name%{$reset_color%} "
    color=%F{red}
    fi

    echo "$color$name$action%f%b "
    }

    setopt prompt_subst
  6. @uasi uasi revised this gist Oct 25, 2009. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,9 @@ autoload -U colors; colors

    function rprompt-git-current-branch {
    local name st color
    if [[ "$PWD" =~ '/\.git(/.*)?$' ]]; then
    return
    fi
    name=`git branch 2> /dev/null | grep '^¥*' | cut -b 3-`
    if [[ -z $name ]]; then
    return
  7. @uasi uasi created this gist Oct 20, 2009.
    30 changes: 30 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #
    # Show branch name in Zsh's right prompt
    #

    autoload -U colors; colors

    function rprompt-git-current-branch {
    local name st color
    name=`git branch 2> /dev/null | grep '^¥*' | cut -b 3-`
    if [[ -z $name ]]; then
    return
    fi
    st=`git status`
    if [[ -n `echo "$st" | grep "^nothing to"` ]]; then
    color=${fg[green]}
    elif [[ -n `echo "$st" | grep "^nothing added"` ]]; then
    color=${fg[yellow]}
    elif [[ -n `echo "$st" | grep "^# Untracked"` ]]; then
    color=${fg_bold[red]}
    else
    color=${fg[red]}
    fi


    echo "%{$color%}$name%{$reset_color%} "
    }

    setopt prompt_subst

    RPROMPT='[`rprompt-git-current-branch`%~]'