#!/bin/sh
# bottom-bars [-k | N...]
#    Display a bottom bar on each of the listed screens, or kill them all.

. $HOME/.xmonad/lib/ws-utils.sh

USAGE="$0 [-hwk] screen...
    -h: print help text
    -w: show weather
    -k: kill bars
"

WEATHER=:
KILL=false
case $1 in
    (-h) echo "$USAGE"; exit;;
    (-w) WEATHER=weather ;;
    (-k) KILL=true; shift;;
    (-l) list; exit;;
esac

# unconditionally kill existing bottom bars.
[ -z "$ZPIDS" ] || kill $ZPIDS
[ -z "$MPIDS" ] || kill $MPIDS
if $KILL; then
    exit 0
fi

status () {
    echo 'screen^fg(white)' `monitor $1` '^fg(#646464)on' `hostname` `$WEATHER` '||' `up` \
	 '||^fg(white)' `date '+%a %Y-%m-%d %I:%M%P'` ' '
}

# Get the width from the xmonad local parameters:
XMLOCAL=$HOME/.xmonad/lib/Local.hs
if [ -z $WIDTH ]; then
    WIDTH=$(grep otherTopBarWidth $XMLOCAL | first_number)
fi

for s in $*; do 
    while :; do status $s; sleep 60; done \
	  | dzen2 $BOTTOM_DZEN_OPTS -fn "$FONT" -dock -geometry +0-0 -w $WIDTH -h 24 -xs $s &
done 

