Guest User

Untitled

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