Skip to content

Instantly share code, notes, and snippets.

@lewis6991
Last active April 17, 2024 17:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewis6991/062108fbe028919daf53f89c60c532ba to your computer and use it in GitHub Desktop.
Save lewis6991/062108fbe028919daf53f89c60c532ba to your computer and use it in GitHub Desktop.
#! /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