Posted By

elliottkember on 10/23/08


Tagged


Versions (?)

Git Branch in Shell Prompt


 / Published in: Bash
 

Stick this in your ~/.bashrc (or ~/.bash_profile on a mac)

  1. function parse_git_branch {
  2. git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
  3. }
  4.  
  5. function proml {
  6. local BLUE="\[\033[0;34m\]"
  7. local RED="\[\033[0;31m\]"
  8. local LIGHT_RED="\[\033[1;31m\]"
  9. local GREEN="\[\033[0;32m\]"
  10. local LIGHT_GREEN="\[\033[1;32m\]"
  11. local WHITE="\[\033[1;37m\]"
  12. local LIGHT_GRAY="\[\033[0;37m\]"
  13. case $TERM in
  14. xterm*)
  15. TITLEBAR='\[\033]0;\u@\h:\w\007\]'
  16. ;;
  17. *)
  18. TITLEBAR=""
  19. ;;
  20. esac
  21.  
  22. PS1="${TITLEBAR}\
  23. [\$(date +%H:%M)]\
  24. [\u@\h:\w$GREEN\$(parse_git_branch)$LIGHT_GRAY]\
  25. $LIGHT_GRAY\$ "
  26. PS2='> '
  27. PS4='+ '
  28. }
  29. proml

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: elliottkember on October 23, 2008

or:

PS1="[\033[38m]\u@\h[\033[01;34m] \w [\033[31m]`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^*/).first || '').gsub(/^* (.+)$/, '(\1) ')\"`[\033[37m]$[\033[00m] "

You need to login to post a comment.