#!/bin/bash

cpu() {
  echo -n "^c#3b414d^^b#7ec7a2^ CPU "
  echo -n "^c#abb2bf^^b#353b45^ $(grep -o "^[^ ]*" /proc/loadavg)"
}

mem() {
  echo -n "^c#3b414d^^b#c7957e^ MEM "
  echo -n "^c#abb2bf^^b#353b45^ $(free -h | awk '/^Mem/ { print $3 }' | sed s/i//g)"
}

clock() {
  echo -n "^c#1e222a^^b#668ee3^ 󱑆 "
  echo -n "^c#1e222a^^b#7aa2f7^ $(date '+%a, %I:%M %p') "
}

root() {
  echo -n "^c#3b414d^^b#ad7ec7^ / "
  echo -n "^c#abb2bf^^b#353b45^ $(df -h / | awk '{if ($1 != "Filesystem") print $4" free"}')"
}

pulse() {
  echo -n "^c#3b414d^^b#7ec0c7^ 墳 "
  echo -n "^c#abb2bf^^b#353b45^ $(awk -F"[][]" '/Left:/ { print $2 }' <(amixer -D pulse sget Master))"
}

spotify() {
  echo -n "^c#3b414d^^b#a7c77e^  "
  echo -n "^c#abb2bf^^b#353b45^ $(playerctl metadata | awk '{if ($2 == "xesam:title") {s = ""; for (i = 3; i <= NF; i++) s = s $i " "; print s}}')"
}

while true; do
  xsetroot -name "^c#cdff59^  $(spotify)$(pulse) $(root) $(cpu) $(mem) $(clock)"
  sleep 2
done
