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

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

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

dbg_msg $"ReadlineCFG Setting:" $"Bellstyle" $(get_key readline/bellstyle)

if [[ $(get_key readline/bellstyle) == audible ]]; then
	rc_add "set bell-style audible"
elif [[ $(get_key readline/bellstyle) == visible ]]; then
	rc_add "set bell-style visible"
elif [[ $(get_key readline/bellstyle) == none ]]; then
	rc_add "set bell-style none"
fi

if [[ $(get_key readline/completion) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Disable-Completion" $"Off"
	rc_add "set disable-completion off"
else
	dbg_msg $"ReadlineCFG Setting:" $"Disable-Completion" $"On"
	rc_add "set disable-completion on"
fi

if [[ $(get_key readline/scrollhz) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Horizontal-Scroll-Mode" $"On"
	rc_add "set horizontal-scroll-mode on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Horizontal-Scroll-Mode" $"Off"
	rc_add "set horizontal-scroll-mode off"
fi

if [[ $(get_key readline/ambiguous) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Show-All-If-Ambiguous" $"On"
	rc_add "set show-all-if-ambiguous on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Show-All-If-Ambiguous" $"Off"
	rc_add "set show-all-if-ambiguous off"
fi

if [[ $(get_key readline/hidden) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Match-Hidden-Files" $"On"
	rc_add "set match-hidden-files on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Match-Hidden-Files" $"Off"
	rc_add "set match-hidden-files off"
fi

if [[ $(get_key readline/ignorecase) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Completion-Ignore-Case" $"On"
	rc_add "set completition-ignore-case on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Completion-Ignore-Case" $"Off"
	rc_add "set completition-ignore-case off"
fi

if [[ $(get_key readline/editing_mode) == emacs ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Editing-Mode Emacs"
	rc_add "set editing-mode emacs"
else
	dbg_msg $"ReadlineCFG Setting:" $"Editing-Mode Vi"
	rc_add "set editing-mode vi"
fi

if [[ $(get_key readline/vstats) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Visible-Stats" $"On"
	rc_add "set visible-stats on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Visible-Stats" $"Off"
	rc_add "set visible-stats off"
fi

if [[ $(get_key readline/completionhz) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Print-Completions-Horizontally" $"On"
	rc_add "set print-completions-horizontally on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Print-Completions-Horizontally" $"Off"
	rc_add "set print-completions-horizontally off"
fi

if [[ $(get_key readline/mark_dirs) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Mark-Directories" $"On"
	rc_add "set mark-directories on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Mark-Directories" $"Off"
	rc_add "set mark-directories off"
fi

if [[ $(get_key readline/mark_sym_dirs) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Mark-Symlinked-Directories" $"On"
	rc_add "set mark-symlinked-directories on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Mark-Symlinked-Directories" $"Off"
	rc_add "set mark-symlinked-directories off"
fi

if [[ $(get_key readline/mark_modlines) == true ]]; then
	dbg_msg $"ReadlineCFG Setting:" $"Mark-Modified-Lines" $"On"
	rc_add "set mark-modified-lines on"
else
	dbg_msg $"ReadlineCFG Setting:" $"Mark-Modified-Lines" $"Off"
	rc_add "set mark-modified-lines off"
fi

dbg_msg $"ReadlineCFG Setting:" $"Completion-Query-Items" $(get_key readline/query_item)
rc_add "set completion-query-items $(get_key readline/query_item)"

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

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

fi
