]> git.phdru.name Git - dotfiles.git/commitdiff
bash_prompt: Show -behind/+ahead counters
authorOleg Broytman <phd@phdru.name>
Mon, 14 Dec 2020 21:02:15 +0000 (00:02 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 18 Dec 2020 16:01:58 +0000 (19:01 +0300)
admin/prog/bash_prompt

index eb152c933d7c369d68685166c8c5d26f5cf3da7d..4e428f398450283bf5d72833cab7e453e776e420 100644 (file)
@@ -69,6 +69,22 @@ prompt_git() {
                       git rev-parse --short HEAD 2> /dev/null || \
                       printf "(unknown)")"
 
+        up=`git rev-parse --abbrev-ref @{u} 2>/dev/null`
+        if [ -n "$up" ]; then
+            local left right
+            set -- `git rev-list --count --left-right @{u}...@`
+            left=$1
+            right=$2
+            if [ "$left" -gt 0 -o "$right" -gt 0 ]; then
+                if [ "$left" -gt 0 ]; then
+                    s="$s-$left"
+                fi
+                if [ "$right" -gt 0 ]; then
+                    s="$s+$right"
+                fi
+            fi
+        fi
+
         [ -n "$s" ] && s=" $s"
         printf " (%s)" "$branchName$s"
     fi