#! /bin/sh

# gtk-themes.sh - Version 1.0
# Allows you to easily change GTK themes
#
# Copyright (c) 2000 Raphaël HALIMI <raph@captainblood.org>
#
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

VERSION="1.0"

# This is the directory where your GTK themes reside. Please change it according
# to your system

# THEMES_DIR=/usr/local/share/themes
THEMES_DIR=/usr/share/themes

# You don't need to change these variables

THEMES=`ls $THEMES_DIR`

NUMBER_OF_THEMES=`echo $THEMES | wc -w`

# Here we go... First we print the themes list

clear ; echo "Available GTK themes :"

echo

COUNT=1

for I in $THEMES ; do
    echo "$COUNT) $I"
    COUNT=$[ $COUNT + 1 ]
done

echo

# Now we wait for an answer, and make some checks

while true ; do
     echo -n "Please enter a number between 1 and $[ $COUNT - 1 ] (or press [ENTER] to exit): "
     read THEME_NUMBER
     if [ -z $THEME_NUMBER ] ; then
        exit
     elif [ "`echo $THEME_NUMBER | grep [^0-9]`" ] ; then
        echo ; echo "Sorry, you typed something else than a number."
     elif [ $THEME_NUMBER -lt 1 -o $THEME_NUMBER -gt $NUMBER_OF_THEMES ] ; then
          echo ; echo "Sorry, this number is out of range."
     else
          break
     fi
done

# Now we check which theme the number entered matches to, and copy the files

COUNT=1

for I in $THEMES ; do
    if [ $THEME_NUMBER = $COUNT ] ; then
       echo ; echo -n "Renaming ~/.gtkrc to ~/.gtkrc.old : "
       mv ~/.gtkrc ~/.gtkrc.old
       echo "done."
       echo -n "Copying new ~/.gtkrc file : "
       cp $THEMES_DIR/$I/gtk/gtkrc ~/.gtkrc
       echo "done." ; echo
       break
    fi
    COUNT=$[ $COUNT + 1 ]
done

echo -n "Theme \"$I\" applied. Press ENTER to quit. "

read

echo
