#!/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.
##################################################################################

## remove gnome-terminal profiles
if type -p gconftool-2 1>/dev/null 2>/dev/null
then
gconftool-2 --recursive-unset /apps/gnome-terminal/profiles/Bashish
gconftool-2 --unset /apps/gnome-terminal/profiles/Bashish
gconftool-2 --type string --set /apps/gnome-terminal/global/default_profile "Default"
NEW_LIST="$(gconftool-2 --get /apps/gnome-terminal/global/profile_list|sed -e 's/Bashish//g' -e 's/,,/,/g' -e 's/\[,/\[/g' -e 's/,\]/\]/g')"
gconftool-2 --type list --list-type=string --set /apps/gnome-terminal/global/profile_list "${NEW_LIST}"
fi
removerc () {
	SHELLRC="$1"
	test -f "${SHELLRC}"||return 1
	cat "$SHELLRC"| grep -v '## line added by bashish' 1>"${SHELLRC}".new
	mv "$SHELLRC".new "${SHELLRC}"
}
removerc "${HOME}"/.bashrc
removerc "${HOME}"/.profile
removerc "${HOME}"/.bash_profile

for BASHISH_PID in "$HOME"/.bashish/tmp/*/pid
do
	if test -f "${BASHISH_PID}"
	then
		read PID<$BASHISH_PID
		kill -9 `cat $BASHISH_PID`
	fi
done

## remove local bashish directory
rm -rf "${HOME}"/.bashish

