Restructure bash git prompt
This commit is contained in:
parent
4128670de2
commit
1a469f9e35
1 changed files with 31 additions and 22 deletions
49
bashrc
49
bashrc
|
@ -29,11 +29,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`
|
||||||
branch=`git branch | grep -Po '(?<=\* )[[:alnum:]]*'`
|
branch=`git branch | grep -Po '(?<=\* )[[:alnum:]]*'`
|
||||||
modif=`git status --short 2>/dev/null | grep -Po '^\s*M' | wc -l`
|
modif=`echo "$status" | grep -Po '^\s*M' | wc -l`
|
||||||
untracked=`git status --short 2>/dev/null | grep -Po '^\?\?' | wc -l`
|
untracked=`echo "$status" | grep -Po '^\?\?' | wc -l`
|
||||||
added=`git status --short 2>/dev/null | grep -Po '^\s*A' | wc -l`
|
added=`echo "$status" | grep -Po '^\s*[A]' | wc -l`
|
||||||
deleted=`git status --short 2>/dev/null | grep -Po '^\s*D' | wc -l`
|
deleted=`echo "$status" | grep -Po '^\s*[D]' | 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*'`
|
||||||
|
@ -43,6 +45,21 @@ git__prompt () {
|
||||||
red='\033[01;31m'
|
red='\033[01;31m'
|
||||||
green='\033[01;32m'
|
green='\033[01;32m'
|
||||||
|
|
||||||
|
# SYNC
|
||||||
|
if [ -z $ahead ] && [ -z $behind ]
|
||||||
|
then
|
||||||
|
echo -ne "" # Nothing to do here
|
||||||
|
elif [ -z $ahead ]
|
||||||
|
then
|
||||||
|
echo -ne " ${yellow}↓${behind}"
|
||||||
|
elif [ -z $behind ]
|
||||||
|
then
|
||||||
|
echo -ne " ${green}↑${ahead}"
|
||||||
|
else
|
||||||
|
echo -ne " ${red}↓${behind}${yellow}↑${ahead}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# BRANCH
|
||||||
if [ -z $branch ]
|
if [ -z $branch ]
|
||||||
then
|
then
|
||||||
branch='#'`git rev-parse --short HEAD`
|
branch='#'`git rev-parse --short HEAD`
|
||||||
|
@ -57,11 +74,12 @@ git__prompt () {
|
||||||
echo -ne " $yellow$branch"
|
echo -ne " $yellow$branch"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 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
|
||||||
else
|
else
|
||||||
echo -ne "$gray:\033[01;33m$modif" # Modified files
|
echo -ne "${gray}:\033[01;33m$modif" # Modified files
|
||||||
fi
|
fi
|
||||||
if [ $added -ne 0 ]
|
if [ $added -ne 0 ]
|
||||||
then
|
then
|
||||||
|
@ -71,22 +89,13 @@ git__prompt () {
|
||||||
then
|
then
|
||||||
echo -ne " ${red}-$deleted"
|
echo -ne " ${red}-$deleted"
|
||||||
fi
|
fi
|
||||||
|
if [ $renamed -ne 0 ]
|
||||||
|
then
|
||||||
|
echo -ne " ${yellow}$renamed→$renamed"
|
||||||
|
fi
|
||||||
if [ $untracked -ne 0 ]
|
if [ $untracked -ne 0 ]
|
||||||
then
|
then
|
||||||
echo -ne "${red}*"
|
echo -ne " ${red}+$untracked"
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z $ahead ] && [ -z $behind ]
|
|
||||||
then
|
|
||||||
echo -ne "" # Nothing to do here
|
|
||||||
elif [ -z $ahead ]
|
|
||||||
then
|
|
||||||
echo -ne "${gray}:${yellow}↓${behind}"
|
|
||||||
elif [ -z $behind ]
|
|
||||||
then
|
|
||||||
echo -ne "${gray}:${green}↑${ahead}"
|
|
||||||
else
|
|
||||||
echo -ne "${gray}:${red}↓${behind}${yellow}↑${ahead}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue