#!/bin/bash

function addFiles()
{
	if [ ${#} -gt 0 ]; then
	{
		for FILE in ${@}; do
		{
		  git add ${FILE}
		}
		done
	}
	else
	{
		  echo "Enter the file to add"
		  read FILE
		  git add ${FILE}
	}
	fi
}

function addAllFiles()
{
	addFiles $(ls .)
}

function commit()
{
	  echo "enter commit message"
	  read commit_message
	  git commit -m "$commit_message"
}

function addAndCommit()
{
	  addAllFiles
	  commit
}

function push()
{
  git push origin master
}

function forcePush()
{
  git push origin master --force
}

function addCommitPush()
{
	addAllFiles
	commit
	push
}

#git pull --rebase origin master

function addNewBranch()
{
	read branch
	git checkout -b $branch
}

function addNewRemote()
{
	echo "Enter the remote name"
	read rname
	echo "Add url"
	read url

	git remote add $rname $url
}

function printMenu()
{
	local -A OPTIONS
	local OPTION_NUM=0
	local OPTION_WIDTH=1
	echo "                              STATUS "
	echo "==============================================================================="
	git status
	echo "==============================================================================="
	echo ""
	echo ""
	echo "ENTER THE OPTION"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="addFiles"      && printf "%-${OPTION_WIDTH}s) ADD A FILE\n"                     "${OPTION_NUM}"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="addAllFiles"   && printf "%-${OPTION_WIDTH}s) ADD ALL FILES\n"                  "${OPTION_NUM}"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="addAndCommit"  && printf "%-${OPTION_WIDTH}s) ADD ALL FILES and COMMIT\n"       "${OPTION_NUM}"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="addCommitPush" && printf "%-${OPTION_WIDTH}s) ADD All files, COMMIT AND PUSH\n" "${OPTION_NUM}"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="push"          && printf "%-${OPTION_WIDTH}s) PUSH the branch\n"                "${OPTION_NUM}"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="forcePush"     && printf "%-${OPTION_WIDTH}s) FORCE PUSH THE branch\n"          "${OPTION_NUM}"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="addNewBranch"  && printf "%-${OPTION_WIDTH}s) ADD new branch\n"                 "${OPTION_NUM}"
	OPTION_NUM=$((${OPTION_NUM} + 1)) && OPTIONS["${OPTION_NUM}"]="addNewRemote"  && printf "%-${OPTION_WIDTH}s) ADD new remote\n"                 "${OPTION_NUM}"
	echo "x. Exit"

	echo "Please select an option: " && read OPTION && echo ""
	${OPTIONS[$OPTION]}
}


SETUP_RUNNING=true

while [ ${SETUP_RUNNING} == true ]; do
{
	printMenu

	if [ ${OPTION} == "x" ]; then
	{
		SETUP_RUNNING=false
	}
	fi
}
done