Re: [RFC/PATCHv2] bash completion: Support "divergence from upstream" warnings in __git_ps1
- From
Michael J Gruber <git@drmicha.warpmail.net>
- Date
- Jun 9, 2010, 20:48 UTC
- Message-ID
- <4C0FFE06.60903@drmicha.warpmail.net>
- In-Reply-To
- <4C0F5C26.5080108@drmicha.warpmail.net>
Michael J Gruber venit, vidit, dixit 09.06.2010 11:17: ...
Show 7 quoted lines
> 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.
...
Show 11 quoted lines
>> + 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