SHARE
TWEET

Untitled

a guest Jan 12th, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. parse_git_branch() {
  12.   git_status="$(git status 2> /dev/null)"
  13.   branch_pattern="On branch ([^${IFS}]*).*"
  14.   remote_pattern="Your branch is (.*) of"
  15.   diverge_pattern="Your branch and (.*) have diverged"
  16.  
  17.   pattern="^(.*)working directory clean"
  18.   if [[ ! ${git_status} =~ $pattern ]]; then
  19.     state="${LIGHT_RED}⚡"
  20.   fi
  21.  
  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.  
  34.   if [[ ${git_status} =~ ${branch_pattern} ]]; then
  35.     branch=${BASH_REMATCH[1]}
  36.     echo " (${branch})${remote}${state}"
  37.   fi
  38.  
  39. }
  40.  
  41.  
  42. function prompt_func() {
  43.     previous_return_value=$?;
  44.     if [ "$TERM" != "linux" -a -z "$EMACS" ]
  45.     then
  46.         TITLEBAR="\[\e]2;\u@\h:\w\a\]"
  47.     else
  48.         TITLEBAR=""
  49.     fi
  50.     prompt="${TITLEBAR}${BLUE}[${YELLOW}\u@\h${RED} \w${GREEN}$(parse_git_branch)${BLUE}]${COLOR_NONE}"
  51.     if test $previous_return_value -eq 0
  52.     then
  53.         PS1="${prompt}${GREEN}\\\$${COLOR_NONE} "
  54.     else
  55.         PS1="${prompt}${LIGHT_RED}\\\$${COLOR_NONE} "
  56.     fi
  57. }
  58.  
  59. PROMPT_COMMAND=prompt_func
RAW Paste Data
Top