#!/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

zenity --question  --text="I want my Window Buttons" --ok-label="Mac Style" --cancel-label="Windows Style"
if [ $? = 0 ] ; then
command=$(gsettings set org.gnome.desktop.wm.preferences button-layout  'close,minimize,maximize:menu')
else
command=$(gsettings set org.gnome.desktop.wm.preferences button-layout 'menu:minimize,maximize,close')
fi

if [ ! -f /usr/bin/metacity ]; then
  zenity --warning --text="<b>You do not appear to have Metacity installed.</b>\n\nThe Compiz GTK window decorator uses Metacity libraries to operate. The Metacity theme is what this tool adjusts.\n\nInstall the metacity package if you would like to use the Compiz GTK window decorator."
fi

button_window() {
  selection=$(
    zenity --height 450 --width 320  --list --ok-label="Apply" --cancel-label="Next" --title="Metacity themes" \
    --column="Current theme: $( if [ $(gsettings get org.gnome.metacity.theme name) == "''" ]; then
        echo Default
      else
        gsettings get org.gnome.metacity.theme name
      fi)" \
    "Compiz GWD default" \
    $(
      for d in /usr/share/themes/*/metacity-1; do
        echo $d | sed 's:/usr/share/themes/::' | sed 's:/metacity-1::'
      done
    )
  )
}

while [ $? = 0 ]; do
if [ "$selection" == "Compiz GWD default" ]; then
  gsettings set org.gnome.metacity.theme name ""
elif [ "$selection" != "" ]; then
  gsettings set org.gnome.metacity.theme name "$selection"
fi
button_window
done

theme_window() {
  selection=$(
    zenity --height 450 --width 320  --list --ok-label="Apply" --cancel-label="Next" --title="GTK themes" \
    --column="Current theme: $( if [ $(gsettings get org.gnome.desktop.interface gtk-theme) == "''" ]; then
        echo Default
      else
        gsettings get org.gnome.desktop.interface gtk-theme
      fi)" \
    "OS-X-Mavericks-1.2" \
    $(
      for d in /usr/share/themes/*/gtk-3.0; do
        echo $d | sed 's:/usr/share/themes/::' | sed 's:/gtk-3.0::'
      done
    )
  )
}

while [ $? = 0 ]; do
if [ "$selection" == "OS-X-Mavericks-1.2" ]; then
  gsettings set org.gnome.desktop.interface gtk-theme ""
elif [ "$selection" != "" ]; then
  gsettings set org.gnome.desktop.interface gtk-theme "$selection"
fi
theme_window
done

icon_window() {
  selection=$(
    zenity --height 450 --width 320  --list --ok-label="Apply" --cancel-label="Close" --title="Icon themes" \
    --column="Current theme: $( if [ $(gsettings get org.gnome.desktop.interface icon-theme) == "''" ]; then
        echo Default
      else
        gsettings get org.gnome.desktop.interface icon-theme
      fi)" \
    "Pearl-Y-Aqua" \
    $(
      for d in /usr/share/icons/*/index.theme; do
        echo $d | sed 's:/usr/share/icons/::' | sed 's:/index.theme::'
      done
    )
  )
}

while [ $? = 0 ]; do
if [ "$selection" == "Pearl-Y-Aqua" ]; then
  gsettings set org.gnome.desktop.interface icon-theme ""
elif [ "$selection" != "" ]; then
  gsettings set org.gnome.desktop.interface icon-theme "$selection"
fi
icon_window
done



IFS=$SAVEIFS
