Guest User

Untitled

a guest
Dec 6th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. # Colors for the prompt
  2. blue="\033[0;34m"
  3. white="\033[0;37m"
  4. green="\033[0;32m"
  5.  
  6. # Brackets needed around non-printable characters in PS1
  7. ps1_blue='\['"$blue"'\]'
  8. ps1_green='\['"$green"'\]'
  9. ps1_white='\['"$white"'\]'
  10.  
  11. parse_git_branch() {
  12. gitstatus=`git status 2> /dev/null`
  13. if [[ `echo $gitstatus | grep "Changes to be committed"` != "" ]]
  14. then
  15. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1***)/'
  16. elif [[ `echo $gitstatus | grep "Changes not staged for commit"` != "" ]]
  17. then
  18. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1**)/'
  19. elif [[ `echo $gitstatus | grep "Untracked"` != "" ]]
  20. then
  21. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1*)/'
  22. elif [[ `echo $gitstatus | grep "nothing to commit"` != "" ]]
  23. then
  24. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
  25. else
  26. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1?)/'
  27. fi
  28. }
  29.  
  30. # Echo a non-printing color character depending on whether or not the current git branch is the master
  31. # Does NOT print the branch name
  32. # Use the parse_git_branch() function for that.
  33. parse_git_branch_color() {
  34. br=$(parse_git_branch)
  35. if [[ $br == "(master)" || $br == "(master*)" || $br == "(master**)" || $br == "(master***)" ]]; then
  36. echo -e "${blue}"
  37. else
  38. echo -e "${green}"
  39. fi
  40. }
  41.  
  42. # No color:
  43. #export PS1="@\h:\W\$(parse_git_branch) \$ "
  44.  
  45. # With color:
  46. export PS1="$ps1_blue@\h:$ps1_white\W\[\$(parse_git_branch_color)\]\$(parse_git_branch) $ps1_blue\$$ps1_white "
Add Comment
Please, Sign In to add comment