#!/bin/bash
##################################################################
#                                                                #
#  Use this stop script to kill spectrum-bass conky.             #
#                                                                #
#  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: 2.6   #
##################################################################

# 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

# Kill all conkies
  rm -f "./tempfiles/load_conkies"
  x=0
  for conky in "${conkies[@]}"
  do
        while read -r loaded
        do
             if [ "$conky" = "$loaded" ]; then
              l=${#conky}
              space=$((40-l))
              pkill -f "$conky"; err=$?
               if [ "$err" = "0" ]; then
                 printf "* $conky"; printf "\e[31m %"$space"s \e[m\n" "killed!"
               elif [ "$err" = "1" ]; then
                 printf "* $conky"; printf "\e[32m %"$space"s \e[m\n" "Not running!"
               fi
              x=1
             fi
        done< <(ls | grep '.conky$')

  done
  if [ "$x" = "0" ]; then echo -e "\n\e[32mNothing to kill.. \e[m\n"; fi

  # Terminate click_event
  pkill -f cava
  pkill -f cava-loop
  echo -e "All terminated...\n"

exit 0
