Skip to content

Instantly share code, notes, and snippets.

@pyatil
Last active January 1, 2016 16:19
Show Gist options
  • Save pyatil/8170016 to your computer and use it in GitHub Desktop.
Save pyatil/8170016 to your computer and use it in GitHub Desktop.

Revisions

  1. pyatil revised this gist Dec 30, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git_prompt.py
    Original file line number Diff line number Diff line change
    @@ -20,11 +20,11 @@ def flush(self):

    def color():
    if 'working directory clean' in git_status:
    return '\033[1;32m[%s]' % branch() # green
    return '${grey}[%s]' % branch() # green
    elif 'Not a git repository' in git_status:
    return ''
    else:
    return '\033[4;31m[%s]' % branch() # red
    return '${red}[%s]' % branch() # red

    def branch():
    try:
  2. pyatil revised this gist Dec 29, 2013. 1 changed file with 12 additions and 3 deletions.
    15 changes: 12 additions & 3 deletions git_prompt.py
    Original file line number Diff line number Diff line change
    @@ -5,15 +5,24 @@
    """
    import re
    import sh

    class my_err_out():
    def __init__(self):
    self.merr = ''
    def write(self, line):
    self.merr += line
    def flush(self):
    pass
    cur_err = my_err_out()
    try:
    git_status = sh.git("status")
    git_status = sh.git("status", _err=cur_err)
    except:
    git_status = ''
    git_status = cur_err.merr

    def color():
    if 'working directory clean' in git_status:
    return '\033[1;32m[%s]' % branch() # green
    elif 'Not a git repository' in git_status:
    return ''
    else:
    return '\033[4;31m[%s]' % branch() # red

  3. pyatil created this gist Dec 29, 2013.
    32 changes: 32 additions & 0 deletions git_prompt.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #/usr/bin/python
    # coding: utf-8
    """
    prompt for status git
    """
    import re
    import sh

    try:
    git_status = sh.git("status")
    except:
    git_status = ''

    def color():
    if 'working directory clean' in git_status:
    return '\033[1;32m[%s]' % branch() # green
    else:
    return '\033[4;31m[%s]' % branch() # red

    def branch():
    try:
    cur_brunch = re.findall("# On branch (.*)", str(git_status))[0]
    except:
    cur_brunch = ''
    return cur_brunch

    if __name__ == '__main__':
    import sys
    if sys.argv[1] == 'color':
    sys.stdout.write(color())
    else:
    print branch()
    27 changes: 27 additions & 0 deletions zshrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    autoload -U colors && colors

    for color in red green yellow blue magenta cyan black white; do
    eval $color='%{$fg_no_bold[${color}]%}'
    #eval ${color}_bold='%{$fg_bold[${color}]%}'
    done
    reset="%{$reset_color%}"

    if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
    host="${black}[${blue}%m${black}] " #SSH
    else
    unset host # no SSH
    fi

    my_git() {
    python /home/snu/Projects/git/git_prompt.py color
    }
    setopt prompt_subst
    # git
    precmd() {
    GIT=$(my_git)
    if [ "$EUID" -eq 0 ]; then
    PROMPT="${host}${red}[${magenta}%2c${red}]${reset} " # root
    else
    PROMPT="${green}[%T]${black} ${host}${black}[${magenta}%2c${black}] $GIT${reset} " # user
    fi
    }