shell: add git agead/behind to PS1

This commit is contained in:
Laila van Reenen 2025-08-17 11:58:32 +02:00
parent 40dcc1b24d
commit 3afa33f28e
Signed by: LailaTheElf
GPG Key ID: 8A3EF0226518C12D

View File

@ -13,8 +13,22 @@ parse_git_branch() {
local b=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$b" != "" ]
then
local behind=$(git rev-list HEAD...@{u} --ignore-submodules --count 2>/dev/null)
local ahead=$(git rev-list @{u}...HEAD --ignore-submodules --count 2>/dev/null)
git diff --cached --exit-code &> /dev/null || b="${b}+"
git diff --exit-code &> /dev/null || b="${b}*"
if [[ "$behind" > 0 || "$ahead" > 0 ]]
then
b="$b ☁ "
if [[ "$ahead" > 0 ]]
then
b="$b+$ahead"
fi
if [[ "$behind" > 0 ]]
then
b="$b-$behind"
fi
fi
fi
echo -n "$b"
}