From fb46679b2a74d34a3ef0c1d98f56ada1b2aa8647 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 28 Dec 2020 16:01:37 +0300 Subject: [PATCH] Refactor(ls-not-pushed): Show behind/ahead counters --- ls-not-pushed | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ls-not-pushed b/ls-not-pushed index bc950e5..8966c59 100755 --- a/ls-not-pushed +++ b/ls-not-pushed @@ -1,2 +1,21 @@ #! /bin/sh -if git branch --verbose | grep -q "ahead\|behind"; then pwd; fi +if git branch --verbose | grep -q "ahead\|behind"; then + up=`git rev-parse --abbrev-ref @{u} 2>/dev/null` + if [ -n "$up" -a "$up" != "@{u}" ]; then + set -- `git rev-list --count --left-right @{u}...HEAD` + left=$1 + right=$2 + s='' + if [ "$left" -gt 0 ]; then + s="$s-$left" + fi + if [ "$right" -gt 0 ]; then + s="$s+$right" + fi + fi + if [ -n "$s" ]; then + echo `pwd`: $s + else + pwd + fi +fi -- 2.39.5