Last active
April 17, 2024 17:35
-
-
Save lewis6991/062108fbe028919daf53f89c60c532ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -e | |
EXTRA_OPTS="--ignore-submodules" | |
mapfile -t status < <(git -c color.status=always status --short $EXTRA_OPTS) | |
if [ ${#status[@]} -eq 0 ]; then | |
printf "\033[93mNothing to commit, working tree clean\033[0m\n" | |
exit | |
fi | |
len=-1 | |
for i in "${!status[@]}"; do | |
status_no_c=$(sed -r 's/^(.[^ ]+) (.*)/\2/g' <<< "${status[i]}") | |
if [ ${#status_no_c} -gt $len ]; then | |
len=${#status_no_c} | |
fi | |
done | |
mapfile -t diff < <(git diff --color $EXTRA_OPTS --stat HEAD 2> /dev/null | sed '$d; s/^ //' | cut -d '|' -f 2) | |
for i in "${!status[@]}"; do | |
cstat=${status[i]} | |
cdiff=${diff[i]} | |
if [ -n "$cdiff" ]; then | |
cstat1=$(sed -r 's/^(.[^ ]+) (.*)/\1/g' <<< "$cstat") | |
cstat2=$(sed -r 's/^(.[^ ]+) (.*)/\2/g' <<< "$cstat") | |
printf "%s %*s │%s\n" "$cstat1" "-$len" "$cstat2" "$cdiff" | |
else | |
printf "%s\n" "$cstat" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment