Guest User

Untitled

a guest
Jan 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. RED="\[\033[0;31m\]"
  2. YELLOW="\[\033[0;33m\]"
  3. GREEN="\[\033[0;32m\]"
  4. BLUE="\[\033[0;34m\]"
  5. LIGHT_RED="\[\033[1;31m\]"
  6. LIGHT_GREEN="\[\033[1;32m\]"
  7. WHITE="\[\033[1;37m\]"
  8. LIGHT_GRAY="\[\033[0;37m\]"
  9. COLOR_NONE="\[\e[0m\]"
  10.  
  11. function parse_git_branch {
  12.  
  13. git rev-parse --git-dir &> /dev/null
  14. git_status="$(git status 2> /dev/null)"
  15. branch_pattern="^# On branch ([^${IFS}]*)"
  16. remote_pattern="# Your branch is (.*) of"
  17. diverge_pattern="# Your branch and (.*) have diverged"
  18. if [[ ! ${git_status} =~ "working directory clean" ]]; then
  19. state="${RED}⚡"
  20. fi
  21. # add an else if or two here if you want to get more specific
  22. if [[ ${git_status} =~ ${remote_pattern} ]]; then
  23. if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
  24. remote="${YELLOW}↑"
  25. else
  26. remote="${YELLOW}↓"
  27. fi
  28. fi
  29. if [[ ${git_status} =~ ${diverge_pattern} ]]; then
  30. remote="${YELLOW}↕"
  31. fi
  32. if [[ ${git_status} =~ ${branch_pattern} ]]; then
  33. branch=${BASH_REMATCH[1]}
  34. echo " (${branch})${remote}${state}"
  35. fi
  36. }
  37.  
  38. function prompt_func() {
  39. previous_return_value=$?;
  40. prompt="${COLOR_NONE}\u@\h ${RED}\w${GREEN}$(parse_git_branch)${COLOR_NONE} "
  41. if test $previous_return_value -eq 0
  42. then
  43. PS1="${prompt}\$ "
  44. else
  45. PS1="${prompt}${RED}\$${COLOR_NONE} "
  46. fi
  47. }
  48.  
  49. PROMPT_COMMAND=prompt_func
Add Comment
Please, Sign In to add comment