#!/bin/zsh

PANEL_FIFO=/tmp/panel-fifo

# If already started, kill utilities
if [ -e "$PANEL_FIFO" ]; then
    rm "$PANEL_FIFO"
    killall panel_bar
    killall bspc
    killall xtitle
    killall clock
    killall battery
    killall volume
fi

mkfifo "$PANEL_FIFO"

bspc subscribe > "$PANEL_FIFO" &
xtitle -sf 'T%s\n' > "$PANEL_FIFO" &
clock -sf 'CD%a %d %b' > "$PANEL_FIFO" &
clock -sf 'CT%H:%M' > "$PANEL_FIFO" &

case $HOST in
    hegp)
        width=3820
        height=30
        size=12
        volume -sf 'VS%s' -d hw:1 > "$PANEL_FIFO" &
        volume -sf 'VI%i' -d hw:1 > "$PANEL_FIFO" &
        ;;
    home)
        width=1900
        height=44
        size=20
        volume -sf 'VS%s' > "$PANEL_FIFO" &
        volume -sf 'VI%i' > "$PANEL_FIFO" &
        ;;
    laptop|hegp-laptop)
        width=1900
        height=24
        size=10
        volume -sf 'VS%s' > "$PANEL_FIFO" &
        volume -sf 'VI%i' > "$PANEL_FIFO" &
        battery -sf 'BS%s' > "$PANEL_FIFO" &
        battery -sf 'BI%i' > "$PANEL_FIFO" &
        ;;
esac

# If given a width, use it
if [[ -n "$1" ]]; then
    width="$1"
fi

cat "$PANEL_FIFO" \
  | panel_bar \
  | lemonbar -g "$width"x"$height"+10+0 \
  -f "monofur\ for\ Powerline:size=$size" \
  -f "FontAwesome:size=$size" \
  -u 0 \
  -B '#00AAAAAA' \
  -F '#FF202020' &

wait
