Joined June 2016
·
vg

vg

`

For git branch

COLORRED="\033[0;31m"
COLOR
YELLOW="\033[0;33m"
COLORGREEN="\033[0;32m"
COLOR
OCHRE="\033[38;5;95m"
COLORBLUE="\033[0;34m"
COLOR
WHITE="\033[0;37m"
COLOR_RESET="\033[0m"

Next, a function for the color formatting:

function gitcolor {
local git
status="$(git status 2> /dev/null)"

if [[ ! $gitstatus =~ "working directory clean" ]]; then
echo -e $COLOR
RED
elif [[ $gitstatus =~ "Your branch is ahead of" ]]; then
echo -e $COLOR
YELLOW
elif [[ $gitstatus =~ "nothing to commit" ]]; then
echo -e $COLOR
GREEN
else
echo -e $COLOR_OCHRE
fi
}

and one for the git branch:

function gitbranch {
local git
status="$(git status 2> /dev/null)"
local onbranch="On branch ([^${IFS}]*)"
local on
commit="HEAD detached at ([^${IFS}]*)"

if [[ $gitstatus =~ $onbranch ]]; then
local branch=${BASHREMATCH[1]}
echo "($branch)"
elif [[ $git
status =~ $oncommit ]]; then
local commit=${BASH
REMATCH[1]}
echo "($commit)"
fi
}

PS1="[$COLORWHITE]\W:" # basename of pwd
PS1+="[\$(git
color)]" # colors git status
PS1+="\$(gitbranch)" # prints current branch
PS1+="[$COLOR
BLUE]\$[$COLOR_RESET] " # '#' for root, else '$'
export PS1
`

Achievements
1 Karma
0 Total ProTip Views