#!/bin/zsh

PANEL_FIFO=/tmp/panel-fifo

if [ $(pgrep -cx panel) -gt 1 ] ; then
  printf "%s\n" "The panel is already running." >&2
  exit 1
fi

trap 'trap - TERM; kill 0' INT TERM QUIT EXIT

[ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
mkfifo "$PANEL_FIFO"

bspc subscribe > "$PANEL_FIFO" &
xtitle -sf 'T%s\n' > "$PANEL_FIFO" &
if [ "$HOST" = "laptop" ];then
  battery -sf 'BI%i' > "$PANEL_FIFO" &
fi
clock -sf 'CD%a %d %b' > "$PANEL_FIFO" &
clock -sf 'CT%H:%M' > "$PANEL_FIFO" &


if [ "$HOST" = "hegp" ];then
  width=1660
  volume -sf 'VS%s' -d hw:1 > "$PANEL_FIFO" &
  volume -sf 'VI%i' -d hw:1 > "$PANEL_FIFO" &
else
  width=1900
  volume -sf 'VS%s' > "$PANEL_FIFO" &
  volume -sf 'VI%i' > "$PANEL_FIFO" &
fi

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

wait
