#!/bin/bash
##################################################################
#                                                                #
#  Use this startup script to load all depending conkies.        #
#  If for some reason one of the conkies is not loaded, all      #
#  conkies will be unloaded.                                     #
#                                                                #
#  Do not change filenames or window titles of the conkies!      #
#  Always use the .conky extention!                              #
#  The scripts depend heavy on them!                             #
#                                                                #
#  Scripted by Koentje   (remon@cobrasoft.nl)                    #
#                                                                #
#  PLEASE DO NOT EDIT THIS SCRIPT !!!                            #
#                                                 version: 1.0   #
##################################################################
./reset-frames

# Get real path to working folder
  scrpath=$(readlink -f $0)
  workdir=$(dirname $scrpath)
  cd "$workdir"


# Get all *.conky files into array
  while read -r files
  do
      conkies+=("${files##*/}")
  done< <(find "$workdir" -maxdepth 1 -type f -name "*.conky" | sort)


# Number of conkies
  for index in ${!conkies[@]}; do
      nr_conkies=$(echo "$index")
  done
  nr_conkies=$((nr_conkies+1))


# Load all conkies
z=1
function load_conkies() {
    for conky in "${conkies[@]}"
    do
        echo -e "loading: $z/$nr_conkies  \e[32m$conky\e[m"
        if [ "$z" -lt "$nr_conkies" ]; then
          conky -c "$conky" &
          sleep 1
        else
          conky -c "$conky"
          ./stop
        fi
      z=$((z+1))
    done
    z=1
}


# Kill all conkies
function kill_conkies() {
   ./stop
}


#ifload &
load_conkies
