config/.local/bin/bash-status-git

23 lines
515 B
Bash
Executable File

#!/bin/bash
if git status &>/dev/null; then
branch=$(git branch --show-current)
if [ -z "$branch" ]; then
echo "(detached)"
exit 0
fi
read -ra counts <<< "$(git rev-list --left-right --count "$branch"...origin/"$branch")"
to_push=${counts[0]}
to_pull=${counts[1]}
extras=$([[ ${counts[0]} -eq 0 && ${counts[1]} -eq 0 ]] || echo " $to_push$to_pull")
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
echo "($branch*$extras)"
else
echo "($branch~$extras)"
fi
fi