#!/bin/sh
#
# gpp - git push

FE8019='\033[38;2;254;128;25m'
NC='\033[0m'

push() {
  # TODO(2025-08-18): random => function
  random=$(awk 'BEGIN { srand(); print int(rand()*32768) }' /dev/null)
  char1=$(echo $((random % 26 + 97)) | awk '{ printf "%c", $1 }')
  char2=$(echo $((random % 26 + 97)) | awk '{ printf "%c", $1 }')

  branch=$(git rev-parse --abbrev-ref HEAD)
  remote=$(git remote get-url --push origin)
  printf '%b\n' "push ${FE8019}${branch}${NC} to ${FE8019}${remote}${NC}?\ntype [${char1}${char2}] to confirm."
  read -r -p "" input

  if [ "${input}" = "${char1}${char2}" ]; then
    git push
  else
    printf '%s\n' "$(basename "$0"): Cancelled." >&2
    exit 1
  fi
}

if ! is-git-repo; then
  printf '%s\n' "Not in a git repo!" >&2
  exit 1
else
  push
fi
