Fix bash git prompt error in fresh repositories

This commit is contained in:
Talia 2018-11-26 15:32:27 +01:00
parent 1a469f9e35
commit 85cb17a8af

23
bashrc
View file

@ -1,3 +1,4 @@
# vim: set noexpandtab :miv #
alias hello='echo "Hello :)"' alias hello='echo "Hello :)"'
alias temp='watch -t -d -n 1 sensors -A coretemp-isa-0000' alias temp='watch -t -d -n 1 sensors -A coretemp-isa-0000'
alias w='watch -t -d -n 1' alias w='watch -t -d -n 1'
@ -29,13 +30,13 @@ git__prompt () {
git rev-parse --show-toplevel > /dev/null 2>&1 git rev-parse --show-toplevel > /dev/null 2>&1
if [ $? = 0 ] if [ $? = 0 ]
then then
status=`git status --short 2>/dev/null` status=`git status --short 2>/dev/null`
branch=`git branch | grep -Po '(?<=\* )[[:alnum:]]*'` branch=`git branch | grep -Po '(?<=\* )[[:alnum:]]*'`
modif=`echo "$status" | grep -Po '^\s*M' | wc -l` modif=`echo "$status" | grep -Po '^\s*M' | wc -l`
untracked=`echo "$status" | grep -Po '^\?\?' | wc -l` untracked=`echo "$status" | grep -Po '^\?\?' | wc -l`
added=`echo "$status" | grep -Po '^\s*[A]' | wc -l` added=`echo "$status" | grep -Po '^\s*[A]' | wc -l`
deleted=`echo "$status" | grep -Po '^\s*[D]' | wc -l` deleted=`echo "$status" | grep -Po '^\s*[D]' | wc -l`
renamed=`echo "$status" | grep -Eo '^\s*R' | wc -l` renamed=`echo "$status" | grep -Eo '^\s*R' | wc -l`
stat=`git branch -vv | grep -P '^\*' | grep -Po '\[.*\]'` stat=`git branch -vv | grep -P '^\*' | grep -Po '\[.*\]'`
ahead=`echo $stat | grep -Po '(?<=ahead )\d*'` ahead=`echo $stat | grep -Po '(?<=ahead )\d*'`
behind=`echo $stat | grep -Po '(?<=behind )\d*'` behind=`echo $stat | grep -Po '(?<=behind )\d*'`
@ -45,7 +46,7 @@ git__prompt () {
red='\033[01;31m' red='\033[01;31m'
green='\033[01;32m' green='\033[01;32m'
# SYNC # SYNC
if [ -z $ahead ] && [ -z $behind ] if [ -z $ahead ] && [ -z $behind ]
then then
echo -ne "" # Nothing to do here echo -ne "" # Nothing to do here
@ -59,22 +60,28 @@ git__prompt () {
echo -ne " ${red}${behind}${yellow}${ahead}" echo -ne " ${red}${behind}${yellow}${ahead}"
fi fi
# BRANCH # BRANCH
if [ -z $branch ] if [ -z $branch ]
then then
branch='#'`git rev-parse --short HEAD` head=`git rev-parse --short HEAD 2>&1`
if [ "$head" == ".*fatal.*" ]
then
branch='#'"$head"
else
branch='{no commits}'
fi
fi fi
if [ $branch = 'master' ] if [ "$branch" = 'master' ]
then then
echo -ne " $blue$branch" echo -ne " $blue$branch"
elif [ ${branch:0:1} = '#' ] elif [ "${branch:0:1}" = '#' ]
then then
echo -ne " $red$branch" echo -ne " $red$branch"
else else
echo -ne " $yellow$branch" echo -ne " $yellow$branch"
fi fi
# CHANGES # CHANGES
if [ $modif = 0 ] if [ $modif = 0 ]
then then
echo -ne # "${gray}:\033[01;36m$modif" # No modified files echo -ne # "${gray}:\033[01;36m$modif" # No modified files