diff --git a/bash-files/bashrc b/bash-files/bashrc index 85cde11..edae292 100644 --- a/bash-files/bashrc +++ b/bash-files/bashrc @@ -7,23 +7,39 @@ shopt -s histappend # update the values of LINES and COLUMNS. shopt -s checkwinsize -parse_git_dirty() { - [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "(*)" -} - -parse_git_stash() { - [[ $(git stash list 2> /dev/null | tail -n1) != "" ]] && echo "(^)" -} - -parse_git_branch () { - git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/" -} - BLACK="\[\033[0;38m\]" RED="\[\033[0;31m\]" RED_BOLD="\[\033[01;31m\]" BLUE="\[\033[01;34m\]" GREEN="\[\033[0;32m\]" +YELLOW="\[\033[0;33m\]" + +parse_git_branch() { + + git rev-parse --git-dir &> /dev/null + git_status="$(git status 2> /dev/null)" + branch_pattern="^# On branch ([^${IFS}]*)" + remote_pattern="# Your branch is (.*) of" + diverge_pattern="# Your branch and (.*) have diverged" + if [[ ! ${git_status} =~ "working directory clean" ]]; then + state="${RED}!" + fi + # add an else if or two here if you want to get more specific + if [[ ${git_status} =~ ${remote_pattern} ]]; then + if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then + remote="${YELLOW}↑" + else + remote="${YELLOW}↓" + fi + fi + if [[ ${git_status} =~ ${diverge_pattern} ]]; then + remote="${YELLOW}↕" + fi + if [[ ${git_status} =~ ${branch_pattern} ]]; then + branch=${BASH_REMATCH[1]} + echo " $RED(${branch})${remote}${state} " + fi +} export CLICOLOR=1 export EDITOR=/usr/bin/mvim @@ -75,6 +91,4 @@ if [ -f /opt/local/etc/bash_completion.d/git ]; then fi # configure my multi-line prompt -export PS1=" -$BLACK[ \u@$RED\h $GREEN\w $RED_BOLD{ \$(parse_git_branch) \$(parse_git_dirty)\$(parse_git_stash) } $BLACK] -> " +export PS1="\n$BLACK[ \u@$RED\h $GREEN\w$RED$(parse_git_branch)$BLACK]\n> "