#!/bin/bash

echo " ==============="
echo "|   Git Config  |"
echo " ==============="
echo
echo -n "Global config or local? (g/l): "
read location
echo
echo "The following will be displayed in your commits..."
echo -n "E-mail Address: "
read email
echo -n "Username: "
read name
echo
if [ "${location}" = "g" ];then
  echo "Review for global config:"
  echo
  echo "Email Address: ${email}"
  echo "Username: ${name}"
  echo
  echo -n "Are these settings correct? (y/n): "
  read confirm

  if [ "${confirm}" = "n" ];then
    echo
    echo "Setup Cancelled...re-run to start over"
    exit 0;
  else
    git config --global user.email ${email}
    git config --global user.name ${name}
    echo
    echo "Saved global config"
    exit 0;
  fi
elif [ "${location}" = "l" ];then
  echo "Review for local config:"
  echo
  echo "Email Address: ${email}"
  echo "Username: ${name}"
  echo
  echo -n "Are these settings correct? (y/n): "
  read confirm

  if [ "${confirm}" = "n" ];then
    echo
    echo "Setup Cancelled...re-run to start over"
    exit 0;
  else
    git config user.email ${email}
    git config user.name ${name}
    echo
    echo "Saved local config"
    exit 0;
  fi
fi
