#!/bin/sh

. $HOME/.barrc

# alpha
a="#cc"
b="#00"

# default colors
bg="${a}${BG}"
fg="${a}${FG}"
sp="${a}${C2}"
red="${a}${C1}"
grn="${a}${C2}"

# default geometry
default_geometry() {
width=$(xdpyinfo | awk '/dimensions:/ { print $2}' | cut -c 1-4)
height=24
offy=0
offx=0

echo "${width}x${height}+${offx}+${offy}"
}

GEOM=${GEOM:-$(default_geometry)}

statusbar() {
	

ver() {
	release=$(head -n1 /etc/release)
	echo $release
}

temp(){
	coretemp=$(envstat | grep "cpu0 temperature: " \
	| awk '{print $3}' | tr '\n' ' ' | cut -b1,2)
	temp="${coretemp}°C"
	echo $temp
}

mem() {
	memtotal="$(($(sysctl -n hw.physmem64) / 1024 / 1024))"
	memused="$(($(vmstat | awk 'END {printf $3}') / 1024))"
	mem="${memused}MB"
	echo $mem
}

ip() {
	ip=$(ip.sh)
	echo $ip
}

batt() {
	batt=$(batt.sh)
	echo $batt
}

vol() {
	vol=$(vol.sh)
	echo $vol
}

dateclock() {
	datetime=$(date +" %a, %b %d")
	echo $datetime
}

clock() {
	time=$(date +" %I:%M")
	echo $time
}

echo %{l}%{F${sp}}" >> "%{F-}%{F${fg}}$(ver)%{F-}%{c}%{F-}%{r}%{F${sp}}" >> "%{F-}%{F${fg}}cpu_temp: $(temp)%{F-}%{F${sp}}" >> "%{F-}%{F${fg}}mem: $(mem)%{F-}%{F${sp}}" >> "%{F-}%{F${fg}}ip: $(ip)%{F-}%{F${sp}}" >> "%{F-}%{F${fg}}batt: $(batt)%{F-}%{F${sp}}" >> "%{F-}%{F${fg}}vol: $(vol)%{F-}%{F${sp}}" >> "%{F-}%{F${fg}} $(dateclock)%{F-}%{F${sp}}" @ "%{F-}%{F${fg}}$(clock)%{F-}%{F${sp}}" "%{F-}
}

while true
 do
   echo "$(statusbar)"
   sleep 1.0
      
 done |  lemonbar -b -d -n $NAME -g $GEOM -f $FONT -B $bg
