Git Branch in Shell Prompt


/ Published in: Bash
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.