#!/bin/bash
##################################################################################
## Bashish, a console theme engine
## Copyright (C) 2005 Thomas Eriksson
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
##################################################################################

function _bashish_themedb
{
	## run in a subshell so we don't have to clean up after all theme loading
	(
	for THEME in $HOME/.bashish/bt/app/*/theme $HOME/.bashish/bt/prompt/theme
	do
		test "x$THEME" = "x$HOME/.bashish/bt/app/*/theme" && exit 10

		. ${THEME}
		THEME_LIST[$n]=${BASHISH_THEME}
		let n++
	done

	for THEMEDIR in $HOME/.bashish/bt/cache/*
	do
		n=0
		REMOVE=1
		while test $n -lt ${#THEME_LIST[*]}
		do
			test x${THEMEDIR##*/} = x${THEME_LIST[$n]}&& { REMOVE=0;break;}
			let n++
		done
		test x${REMOVE} = x1 && {
			rm -f ${THEMEDIR}/*
			rm -r ${THEMEDIR}
		}
	done 2>/dev/null
	)
}
