Advertisement
Guest User

Untitled

a guest
May 28th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. # color prompt to include branch information
  2. function color_my_prompt {
  3. local __user_and_host="\[\033[01;32m\]\u@\h"
  4. local __cur_location="\t\w"
  5. local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\ \(\\\\\1\)\/`'
  6. local __prompt_tail=">"
  7. local __last_color="\[\033[00m\]"
  8.  
  9. RED="\[\033[0;31m\]"
  10. YELLOW="\[\033[0;33m\]"
  11. LPURPLE="\[\033[0;35m\]"
  12. GREEN="\[\033[0;32m\]"
  13. LBLUE="\[\033[0;34m\]"
  14.  
  15. # Capture the output of the "git status" command.
  16. git_status="$(git status 2> /dev/null)"
  17.  
  18. # Set color based on clean/staged/dirty.
  19. if [[ ${git_status} =~ "working directory clean" ]]; then
  20. #state="${GREEN}"
  21. state="${LBLUE}"
  22. elif [[ ${git_status} =~ "Changes to be committed" ]]; then
  23. #state="${YELLOW}"
  24. state="${LPURPLE}"
  25. else
  26. state="${RED}"
  27. fi
  28.  
  29. export PS1="$__cur_location${state}$__git_branch$__last_color$__prompt_tail "
  30. }
  31. # Tell bash to execute this function just before displaying its prompt.
  32. PROMPT_COMMAND=color_my_prompt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement