Wednesday, April 24, 2013

show git branch on bash prompt

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions
# show git branch
parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[00m\]\u@\h\[\033[01;33m\] \w \[\033[31m\]\$(parse_git_branch)\[\033[00m\]$\[\033[00m\] "

5 comments:

  1. http://misc.flogisoft.com/bash/tip_colors_and_formatting all bash colors

    ReplyDelete
  2. if you wanna modify directory colors, don't touch the /etc/DIR_COLOR file. what you can do is only view it with vim, and find out the dirctory parameters, and make another file called ~/.dir_colors and over wirte the paramters. For example :

    DIR 01;34 # directory
    LINK 01;36 # symbolic link (If you set this to 'target' instead of a
    # numerical value, the color is as for the file pointed to.)
    # MULTIHARDLINK 00 # regular file with more than one link
    #FIFO 40;33 # pipe
    # SOCK 01;35 # socket
    # DOOR 01;35 # door
    # BLK 40;33;01 # block device driver
    # CHR 40;33;01 # character device driver
    # ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file
    # MISSING 01;05;37;41 # ... and the files they point to
    # SETUID 37;41 # file that is setuid (u+s)
    # SETGID 30;43 # file that is setgid (g+s)
    # CAPABILITY 30;41 # file with capability
    STICKY_OTHER_WRITABLE 01;34 # dir that is sticky and other-writable (+t,o+w)
    OTHER_WRITABLE 01;34 # dir that is other-writable (o+w) and not sticky
    STICKY 01;34 # dir with the sticky bit set (+t) and not other-writable

    ReplyDelete
  3. export PS1="\[\033[00m\]\u\[\033[01;32m\]@\h\[\033[01;34m\] \w \[\033[31m\]\$(parse_git_branch)\[\033[00m\]$\[\033[00m\] "

    ReplyDelete
  4. # show git branch
    parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
    }
    export PS1='\[\033[01;32m\]\u\[\033[01;34m\]::\[\033[01;31m\]\h \[\033[00;34m\]{ \[\033[01;34m\]\w \[\033[00;34m\]}\[\033[01;32m\]-> \[\033[00m\]'

    ReplyDelete
  5. export PS1="\[\033[00m\]\u\[\033[01;36m\] -\t- \[\033[00m\]\h [\w] $"

    ReplyDelete