Skip to content

Instantly share code, notes, and snippets.

@rawnly
Created April 30, 2021 13:41
Show Gist options
  • Save rawnly/fadc39d6e1e560f6b98092496f68f669 to your computer and use it in GitHub Desktop.
Save rawnly/fadc39d6e1e560f6b98092496f68f669 to your computer and use it in GitHub Desktop.
#!/bin/zsh
TEXT_DIM="\e[2m"
TEXT_BOLD="\e[1m"
TEXT_UNDERLINE="\e[4m"
TEXT_RED="\e[91m"
TEXT_BLACK="\e[30m"
TEXT_DEFAULT="\e[39m"
TEXT_RESET="\e[0m"
TEXT_YELLOW="\e[33m"
DEFAULT_BG="\e[49m"
YELLOW_BG="\e[43m"
RED_BG="\e[41m"
is_ok=0
commitMessage=$1
NEXT="$(git branch | grep '*' | grep -Eo 'NEXT-[0-9]+')"
[ "$(git status -s)" = "" ] && echo -e "${YELLOW_BG}${TEXT_BLACK}WARNING: Clean working tree. Nothing to commit." 1>&2 && exit 1;
test -z "$commitMessage" && echo "${RED_BG}ERROR: Please provide a commit message." 1>&2 && exit 1;
message="${NEXT}: ${commitMessage}"
has_next=true
if [ -z "$NEXT" ]; then
echo -e "${YELLOW_BG}${TEXT_BLACK}WARNING: Not a NEXT branch${TEXT_RESET}${TEXT_DEFAULT}";
message="${commitMessage}"
has_next=false
fi
prompt() {
echo ""
echo -e "Press ${TEXT_BOLD}[ENTER]${TEXT_RESET} to continue or ${TEXT_BOLD}[ESC]${TEXT_RESET} to abort."
echo -e "${TEXT_DIM}Press ${TEXT_BOLD}[d]${TEXT_RESET} ${TEXT_DIM}to run diff${TEXT_RESET}${TEXT_DEFAULT}"
echo ""
read -srk key
}
echo ""
echo -e "Committing the following files with: [ ${TEXT_BOLD}${TEXT_UNDERLINE}${TEXT_YELLOW}${message}${TEXT_RESET}${TEXT_DEFAULT} ]"
echo -e "${TEXT_DIM}-----------------------${TEXT_RESET}"
git status -s
echo -e "${TEXT_DIM}-----------------------${TEXT_RESET}"
prompt;
while true;
do
case $key in
"d")
echo -e "> Opening ${TEXT_BOLD}DIFF${TEXT_RESET}"
git diff
prompt;
;;
$'\e' | q)
is_ok=0;
break
;;
$'\x0a')
is_ok=1;
break
;;
*)
prompt;
;;
esac
done
[ $is_ok -eq 0 ] && echo -e "${RED_BG}Operation Aborted." 1>&2 && exit 1;
git add -A .
git commit -a -m "${message}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment