configfiles

All my config files for making a linux box friendlier
git clone git://git.hellocld.com/configfiles
Log | Files | Refs | README

commit dbf1e1cfe96e2e6f60e41aec1616cd1d4f2db32a
parent 7d5fa84f6118b6f681e432552e63cdb01b150a3c
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Sat, 28 Dec 2019 13:46:59 -0500

Experimenting with git status info in the prompt

Diffstat:
Mbashrc | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/bashrc b/bashrc @@ -29,6 +29,7 @@ alias diff='diff --color=auto' # Fun figlet nonsense to sex up the shell figlet -f smslant "Hello `whoami`" fortune +echo "" PROMPT_COMMAND=__prompt_command @@ -44,6 +45,21 @@ __prompt_command() { # Base PS1 config PS1="[${GREEN}\A${RESET} \u@\h] ${BLUE}`pwd`${RESET}" + # Customize for git repos + if [ -d .git ]; then + local BRANCH=$(git rev-parse --abbrev-ref HEAD) + local STATUS=$(git status --porcelain) + local LOCAL_STAT="" + if [ $(echo ${STATUS} | wc -c) == 1 ]; then + LOCAL_STAT="${GREEN}✓${RESET}" + else + LOCAL_STAT+="${GREEN}▪$(echo ${STATUS} | grep -i "^[M,A][ ]" | wc -l)${RESET}" + LOCAL_STAT+="${RED}+$(echo ${STATUS} | grep -i "^[ ][M,A]" | wc -l)${RESET}" + LOCAL_STAT+="${BLUE}…$(echo ${STATUS} | grep ?? | wc -l)${RESET}" + fi + PS1+=" [${BRANCH} | ${LOCAL_STAT}]" + fi + # Customize exit code output if [ $EXIT != 0 ]; then PS1+=" ${RED}[${EXIT}]${RESET} "