#!/bin/bash
##################################################################################
## Bashish, a console theme engine
## Copyright (C) 2010 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_unpack
{
	## set theme name
	case "$1" in
	none) THEME=none;;
	*) _bashish_find "$1"||errorhandler 30
	esac


	DESTDIR="${HOME}"/.bashish/prompt
	test "x${BTAPP}" != x && DESTDIR="$HOME/.bashish/app/${BTAPP##*/}"
	if test -d "${DESTDIR}"
	then
		rm "${DESTDIR}"/* 2>/dev/null
	else
		mkdir -p "${DESTDIR}"
	fi
	
	
	## check for presence of a theme dir and a theme string to load
	## check for special theme strings
	case "${THEME}" in
	none)
		test "x$BTAPP" = x && rm "${HOME}/.bashish/launcher/${BTAPP}" ## remove launcher
		rm -rf "${DESTDIR}" ## remove themedir
	;;
	*)
		cp "${THEMEFILE}"/* "${DESTDIR}"/
		RETURN=0

		if test x"${BTAPP}" = x
		then
			printf "#"'!'"/bin/sh\n_bashish_prompt_argv()\n{\n:\n" >"${DESTDIR}/argv.sh"
			INDEX=1
			while test ${INDEX} -lt ${BASHISH_ARGC}
			do
				printf "printf \"\\\\\"${BASHISH_ARGV[$INDEX]}\\\\\" \"\n"
				let INDEX++
			done >>"${DESTDIR}"/argv.sh
			printf "\n}\n" >>"${DESTDIR}"/argv.sh
		fi
	esac
}
