#!/usr/local/bin/ksh93

#
# This file is a part of the NsCDE - Not so Common Desktop Environment
# Author: Hegel3DReloaded
# Licence: GPLv3
#

[ -z /usr/local ] && exit 2
MARCH=$(uname -m)

function find_colors
{
   if [ "x$NSCDE_PALETTE" != "x" ]; then
      if [ -r "$FVWM_USERDIR/palettes/${NSCDE_PALETTE}.dp" ]; then
         palfile="$FVWM_USERDIR/palettes/${NSCDE_PALETTE}.dp"
      else
         if [ -r "/usr/local/share/nscde/palettes/${NSCDE_PALETTE}.dp" ]; then
            palfile="/usr/local/share/nscde/palettes/${NSCDE_PALETTE}.dp"
         fi
      fi

      if [[ "$NSCDE_PALETTE_NCOLORS" != @(4|8) ]]; then
         NSCDE_PALETTE_NCOLORS=4
      fi

      if [ "x$palfile" != "x" ]; then
         /usr/local/libexec/nscde/nscde_palette_colorgen.py \
          -n ${NSCDE_PALETTE_NCOLORS} \
          -p /usr/local/share/nscde/palettes/${NSCDE_PALETTE}.dp -sl | \
          egrep '(ts|bs)_color_3' | while IFS=" " read name value
         do
            eval "${name}"="${value}"
         done
         if [ "x$bs_color_3" == "x" ]; then
            bs_color_3="black"
         fi
         if [ "x$ts_color_3" == "x" ]; then
            ts_color_3="red"
         fi
      else
         bs_color="black"
         ts_color="red"
      fi
   else
      bs_color="black"
      ts_color="red"
   fi
}

find_colors

if [ -x /usr/local/bin/fpclock ]; then
   exec /usr/local/bin/fpclock -H $bs_color_3 -S $ts_color_3 "$@"
else
   pclock=$(whence -p pclock)
   if [ "x$pclock" != "x" ]; then
      exec $pclock -H black -S red --hour-hand-length=15 --minute-hand-length=20 --second-hand-length=22 "$@"
   fi
fi

