#!/bin/bash
# Get memory info from /proc/meminfo
mem_total=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
mem_available=$(awk '/MemAvailable/ {print $2}' /proc/meminfo)
# If MemAvailable isn't available (older kernels), calculate it
if [ -z "$mem_available" ]; then
    mem_free=$(awk '/MemFree/ {print $2}' /proc/meminfo)
    mem_buffers=$(awk '/Buffers/ {print $2}' /proc/meminfo)
    mem_cached=$(awk '/^Cached/ {print $2}' /proc/meminfo)
    mem_available=$((mem_free + mem_buffers + mem_cached))
fi
# Calculate used percentage
mem_used=$((mem_total - mem_available))
mem_percent=$((mem_used * 100 / mem_total))
# Color coding similar to your battery script
if [ "$mem_percent" -ge 90 ]; then
    printf "^bg(FF0000)MEM: %d%%^bg()" "$mem_percent"
elif [ "$mem_percent" -ge 75 ]; then
    printf "^fg(FFFF00)MEM: %d%%^fg()" "$mem_percent"
else
    printf "MEM: %d%%" "$mem_percent"
fi
