#!/bin/bash
#########################################################
#                                                       #
# This is BashStyle-NG                                  #
#                                                       #
# Licensed under GNU GENERAL PUBLIC LICENSE v3          #
#                                                       #
# Copyright 2007 - 2011 Christopher Bratusek            #
#                                                       #
#########################################################

MODULES=( internal/gconf internal/misc internal/logging
	  generate/bash generator/nano generator/readline generator/vim )

for mod in ${MODULES[@]}; do
	source $BSNG_RC_DIR/$mod
done

export CURRENT_DATE="$(date +%Y-%m-%d_%I-%M)"

if [[ ! -e $HOME/bashstyle ]]; then
	mkdir -p $HOME/bashstyle
fi

case $1 in
	*bash)
		export BSNG_RC_GEN=true
		export RC_FILE=$HOME/bashstyle/bashrc.bs-ng-$CURRENT_DATE
		generate_bashrc
		if [[ $? == 0 ]]; then
			echo -e "${ewhite}Bash configuration saved as: ${eiceblue}$HOME/bashstyle/bashrc.bs-ng-$CURRENT_DATE\
				\n${ewhite}copy it to ${egreen}$HOME/.bashrc${ewhite} to use it. (disable BashStyle in Bashstyle-NG,\
				\nbefore using this config-file - settings will be overwritten else)\n"
			tput sgr0
		fi
		unset BSNG_RC_GEN RC_FILE
	;;

	*readline)
		export BSNG_RC_GEN=true
		export RC_FILE=$HOME/bashstyle/readline-rc.bs-ng-$CURRENT_DATE
		generate_readlinerc
		if [[ $? == 0 ]]; then
			echo -e "${ewhite}Readline configuration saved as ${eiceblue}$HOME/bashstyle/readline-rc.bs-ng-$CURRENT_DATE\
				\n${ewhite}copy it to ${egreen}$HOME/.inputrc${ewhite} to use it (disable ReadlineCFG in Bashstyle-NG,\
				\nbefore using this config-file - file will be overwritten else)\n"
			tput sgr0
		fi
		unset BSNG_RC_GEN RC_FILE
	;;

	*vim)
		export BSNG_RC_GEN=true
		export RC_FILE=$HOME/bashstyle/vim-rc.bs-ng-$CURRENT_DATE
		generate_vimrc
		if [[ $? == 0 ]]; then
			echo -e "${ewhite}Vim configuration saved as: ${eiceblue}$HOME/bashstyle/vim-rc.bs-ng-$CURRENT_DATE\
				\n${ewhite}copy it to ${egreen}$HOME/.vimrc${ewhite} to use it (disable VimCFG in BashStyle-NG,\
				\nbefore using this config-file - file will be overwritten else)\n"
			tput sgr0
		fi
		unst BSNG_RC_GEN RC_FILE
	;;

	*nano)
		export BSNG_RC_GEN=true
		export RC_FILE=$HOME/bashstyle/nano-rc.bs-ng-$CURRENT_DATE
		generate_nanorc
		if [[ $? == 0 ]]; then
			echo -e "${ewhite}Nano configuration saved as: ${eiceblue}$HOME/bashstyle/nano-rc.bs-ng-$CURRENT_DATE\
				\n${ewhite}copy it to ${egreen}$HOME/.nanorc${ewhite} to use it (disable NanoCFG in BashStyle-NG,\
				\nbefore using this config-file - file will be overwritten else)\n"
			tput sgr0
		fi
		unset BSNG_RC_GEN RC_FILE
	;;

	*all)
		rcgenerator --bash
		rcgenerator --readline
		rcgenerator --vim
		rcgenerator --nano
	;;

	*)

		echo -e "\n${ewhite}Usage:\n"
		echo -e "${eorange}rcgenerator${ewhite} |${egreen} --bash ${eiceblue}[generate standalone BASH config]\
		\n${eorange}rcgenerator${ewhite} |${egreen} --readline ${eiceblue}[generate standalone Readline config]\
		\n${eorange}rcgenerator${ewhite} |${egreen} --vim ${eiceblue}[generate standalone VIm config]\
		\n${eorange}rcgenerator${ewhite} |${egreen} --nano ${eiceblue}[generate standalone Nano config]\
		\n${eorange}rcgenerator${ewhite} |${egreen} --all ${eiceblue}[all above at once]\n" | column -t
		echo ""

	;;
esac

unset CURRENT_DATE
