Subject: Re: [RFC/PATCHv2] bash completion: Support "divergence from upstream" warnings in __git_ps1

From: Michael J Gruber <[email-masked]>
Date: Wed, 09 Jun 2010 22:48:06 +0200

Michael J Gruber venit, vidit, dixit 09.06.2010 11:17:
...
> An alternative would be to use something like
> myrepo:master+5-3
> 
> The numbers should make this distinguishable from the "--cached +". Of
> course it eats up more space and is slightly confusing unless it is read
> master = upstream + 5 -3.
> OTOH it is very analogous to status -s and branch -vv.
...
>> +				if p="$( git rev-list \
>> +						--left-right "$upstream"...HEAD 2>/dev/null )"
> 
> Here you have all the info to do a "grep \<|wc -l" etc. instead of the
> below if you go for the +5-3.
> 
>> +				then
>> +					case "$p" in
>> +						\<*\>*|\>*\<* ) p="<>" ;;
>> +						*\<*          ) p="<"  ;;
>> +						*\>*          ) p=">"  ;;

I mean something like this

					case "$p" in
						\<*\>*|\>*\<* ) p="+"$(echo "$p"|grep ">"|wc -l)"-"$(echo
"$p"|grep "<"|wc -l)  ;;
						*\<*          ) p="-"$(echo "$p"|grep "<"|wc -l)  ;;
						*\>*          ) p="+"$(echo "$p"|grep ">"|wc -l)  ;;

with

		printf "${1:- (%s)}" "$c${b##refs/heads/}$p${f:+ $f}$r"

resulting in a prompt like

[mjg@localhost git (mjg/sane-symlink-diff+4-153 *+%)]

on my branch "mjg/sane-symlink-diff".

Cheers,
Michael