function gitcolor {
local gitstatus="$(git status 2> /dev/null)"
if [[ ! $gitstatus =~ "working directory clean" ]]; then
echo -e $COLORRED
elif [[ $gitstatus =~ "Your branch is ahead of" ]]; then
echo -e $COLORYELLOW
elif [[ $gitstatus =~ "nothing to commit" ]]; then
echo -e $COLORGREEN
else
echo -e $COLOR_OCHRE
fi
}
and one for the git branch:
function gitbranch {
local gitstatus="$(git status 2> /dev/null)"
local onbranch="On branch ([^${IFS}]*)"
local oncommit="HEAD detached at ([^${IFS}]*)"
if [[ $gitstatus =~ $onbranch ]]; then
local branch=${BASHREMATCH[1]}
echo "($branch)"
elif [[ $gitstatus =~ $oncommit ]]; then
local commit=${BASHREMATCH[1]}
echo "($commit)"
fi
}
PS1="[$COLORWHITE]\W:" # basename of pwd
PS1+="[\$(gitcolor)]" # colors git status
PS1+="\$(gitbranch)" # prints current branch
PS1+="[$COLORBLUE]\$[$COLOR_RESET] " # '#' for root, else '$'
export PS1
`
`
For git branch
COLORRED="\033[0;31m"
COLORYELLOW="\033[0;33m"
COLORGREEN="\033[0;32m"
COLOROCHRE="\033[38;5;95m"
COLORBLUE="\033[0;34m"
COLORWHITE="\033[0;37m"
COLOR_RESET="\033[0m"
Next, a function for the color formatting:
function gitcolor {
local gitstatus="$(git status 2> /dev/null)"
if [[ ! $gitstatus =~ "working directory clean" ]]; then
echo -e $COLORRED
elif [[ $gitstatus =~ "Your branch is ahead of" ]]; then
echo -e $COLORYELLOW
elif [[ $gitstatus =~ "nothing to commit" ]]; then
echo -e $COLORGREEN
else
echo -e $COLOR_OCHRE
fi
}
and one for the git branch:
function gitbranch {
local gitstatus="$(git status 2> /dev/null)"
local onbranch="On branch ([^${IFS}]*)"
local oncommit="HEAD detached at ([^${IFS}]*)"
if [[ $gitstatus =~ $onbranch ]]; then
local branch=${BASHREMATCH[1]}
echo "($branch)"
elif [[ $gitstatus =~ $oncommit ]]; then
local commit=${BASHREMATCH[1]}
echo "($commit)"
fi
}
PS1="[$COLORWHITE]\W:" # basename of pwd
PS1+="[\$(gitcolor)]" # colors git status
PS1+="\$(gitbranch)" # prints current branch
PS1+="[$COLORBLUE]\$[$COLOR_RESET] " # '#' for root, else '$'
export PS1
`