#!/bin/bash
# slit -- Christopher Mahmood <ckm@suse.com>
# creates the slit thing in Blackbox or Openbox.
# Only only aimed at die-hard windowmaker/afterstep fans, and manual
# compilation of some apps might be needed.

if [ "$(basename $WINDOWMANAGER)" != "blackbox" -a \
     "$(basename $WINDOWMANAGER)" != "openbox" ] ; then
  	echo "This only works with blackbox or openbox."
	echo "Please set \$WINDOWMANAGER"
	exit 1
fi

declare -a apps
apps[5]="wmweather -s EKOD -metric -mmHg -beaufort"
apps[4]="wmfire -B"
apps[3]="wmcalclock -24"
apps[2]="asload -withdrawn -shape -u 1"
apps[1]="asmail -withdrawn"

num_apps=${#apps[@]}

case "$1" in
	start)
		while [ $num_apps -gt 0 ]; do
			LC_NUMERIC=C sleep 0.1
			app="${apps[$num_apps]}"
			test "$app" && exec $app &
			let "num_apps -= 1"
		done
		;;
	stop)
		while [ $num_apps -gt 0 ]; do
			killall $(echo ${apps[$num_apps]} | awk '{print $1}') &
			let "num_apps -= 1"
		done
		;;
	restart)
		$0 stop
		$0 start
		;;
		*)
	echo "Usage: `basename $0` {start|stop|restart}"
	exit 1
	;;
esac

exit 0
