Guest User

Untitled

a guest
Apr 20th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. export CLICOLOR=1
  4.  
  5. BLACK="\[\033[0;0m\]"
  6. BLUE="\[\033[0;34m\]"
  7. BROWN="\[\033[0;33m\]"
  8. COLOR_NONE="\[\e[0m\]"
  9. CYAN="\[\033[0;36m\]"
  10. GREEN="\[\033[0;32m\]"
  11. LIGHT_GRAY="\[\033[1;37m\]"
  12. LIGHT_GREEN="\[\033[1;32m\]"
  13. LIGHT_RED="\[\033[1;31m\]"
  14. PURPLE="\[\033[0;35m\]"
  15. RED="\[\033[0;31m\]"
  16. WHITE="\[\033[0;37m\]"
  17. YELLOW="\[\033[0;33m\]"
  18.  
  19. function tree {
  20. find ${1:-.} -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
  21. }
  22.  
  23. function parse_git_branch {
  24. git rev-parse --git-dir &> /dev/null
  25. git_status="$(git status 2> /dev/null)"
  26. git_stash="$(git stash list 2> /dev/null)"
  27. branch_pattern="^# On branch ([^${IFS}]*)"
  28. remote_pattern="# Your branch is (.*) of"
  29. diverge_pattern="# Your branch and (.*) have diverged"
  30. if [[ ! ${git_status}} =~ "working directory clean" ]]; then
  31. state="${RED}⚡"
  32. fi
  33. if [[ -n ${git_stash} ]]; then
  34. stash="${RED}*"
  35. fi
  36. # add an else if or two here if you want to get more specific
  37. if [[ ${git_status} =~ ${remote_pattern} ]]; then
  38. if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
  39. remote="${YELLOW}↑"
  40. else
  41. remote="${YELLOW}↓"
  42. fi
  43. fi
  44. if [[ ${git_status} =~ ${diverge_pattern} ]]; then
  45. remote="${YELLOW}↕"
  46. fi
  47. if [[ ${git_status} =~ ${branch_pattern} ]]; then
  48. branch=${BASH_REMATCH[1]}
  49. echo " (${branch})${remote}${stash}${state}"
  50. fi
  51. }
  52.  
  53. function prompt_func() {
  54. previous_return_value=$?;
  55. TITLEBAR='\[\e]2;\w\a\]'
  56. prompt="${TITLEBAR}${PURPLE}\u@\h ${BLUE}\W${GREEN}$(parse_git_branch)${COLOR_NONE} "
  57. if test $previous_return_value -eq 0
  58. then
  59. PS1="${prompt}➔ "
  60. else
  61. PS1="${prompt}${RED}➔${COLOR_NONE} "
  62. fi
  63. }
  64.  
  65. PROMPT_COMMAND=prompt_func
Add Comment
Please, Sign In to add comment