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

if [[ -e $HOME/.nanorc && ( ! -w $HOME/.nanorc || ! -r $HOME/.nanorc ) ]]; then
	ERR_MSG+="\n * $HOME/.nanorc is not fully acccessible! -- adjust permissions."
else

if [[ ! $BSNG_RC_GEN ]]; then
	export RC_FILE=$HOME/.nanorc.$(date +%I-%M-%S)
fi

if [[ $(get_key nano/auto_indent) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Auto-Indention" $"On"
	rc_add "set autoindent"
else
	dbg_msg $"NanoCFG Setting:" $"Auto-Indention" $"Off"
	rc_add "unset autoindent"
fi

if [[ $(get_key nano/backup) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Autosave" $"On"
	rc_add "set backup"
else
	dbg_msg $"NanoCFG Setting:" $"Autosave" $"Off"
	rc_add "unset backup"
fi

if [[ $(get_key nano/bold_text) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Bold-Text" $"On"
	rc_add "set boldtext"
else
	dbg_msg $"NanoCFG Setting:" $"Bold-Text" $"Off"
	rc_add "unset boldtext"
fi

if [[ $(get_key nano/case_sensitive) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Case-Sensitive" $"On"
	rc_add "set casesensitive"
else
	dbg_msg $"NanoCFG Setting:" $"Case-Sensitive" $"Off"
	rc_add "unset casesensitive"
fi

if [[ $(get_key nano/const) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Show-Position" $"On"
	rc_add "set const"
else
	dbg_msg $"NanoCFG Setting:" $"Show-Position" $"Off"
	rc_add "unset const"
fi

if [[ $(get_key nano/more_space) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"More-Space" $"On"
	rc_add "set morespace"
else
	dbg_msg $"NanoCFG Setting:" $"More-Space" $"Off"
	rc_add "unset morespace"
fi

if [[ $(get_key nano/nohelp) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"No-Help" $"On"
	rc_add "set nohelp"
else
	dbg_msg $"NanoCFG Setting:" $"No-Help" $"Off"
	rc_add "unset nohelp"
fi

if [[ $(get_key nano/history) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"History Log:" $"On"
	rc_add "set historylog"
else
	dbg_msg $"NanoCFG Setting:" $"History Log:" $"Off"
	rc_add "unset historylog"
fi

if [[ $(get_key nano/rebind_del) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Rebind Delete:" $"On"
	rc_add "set rebinddelete"
else
	dbg_msg $"NanoCFG Setting:" $"Rebind Delete:" $"Off"
	rc_add "unset rebinddelete"
fi

if [[ $(get_key nano/rebind_kp) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Rebind Keypad:" $"On"
	rc_add "set rebindkeypad"
else
	dbg_msg $"NanoCFG Setting:" $"Rebind Keypad:" $"Off"
	rc_add "unset rebindkeypad"
fi

if [[ $(get_key nano/use_colors) == true ]]; then
	dbg_msg $"NanoCFG Setting:" $"Colors" $"On"
	COLOR_FILES="$(ls /usr/share/nano/*.nanorc)"
	for file in $COLOR_FILES; \
		do rc_add "include \"$file\""; \
	done
else	dbg_msg $"NanoCFG Setting:" $"Colors" $"Off"
fi

if [[ ! $BSNG_RC_GEN ]]; then
	mv $RC_FILE $HOME/.nanorc
	unset RC_FILE
fi

dbg_msg $"NanoCFG Loading:" $"BashStyle-NG"

fi
