#!/bin/bash

SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

#boot compton if it exists
if [ -x "$(command -v compton)" ]; then
  compton &> /dev/null & 
fi

#set background
if [ -x "$(command -v feh)" ]; then
  feh --bg-scale $SCRIPTPATH/background.jpg
fi

echo "LoadTheme $SCRIPTPATH/theme.toml" > $XDG_RUNTIME_DIR/leftwm/commands.pipe

#boot polybar based on the number of monitors found
if [ -x "$(command -v polybar)" ]; then
  pkill polybar
  monitors="$(polybar -m | sed s/:.*// | tac)"
  while read -r display; do
    MONITOR=$display polybar -c "$SCRIPTPATH/polybar.config" mainbar &> /dev/null &
  done <<< "$monitors"
  exit 0
fi
