Files
nixos/home/.local/usr/bin/dwlb-status.sh
2025-09-19 11:44:17 -04:00

61 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# dwlb status script for system information
# This script runs in a loop and updates the dwlb status bar
# Get all available outputs
get_outputs() {
wlr-randr | grep '^[^ ]' | cut -d' ' -f1
}
while true; do
# Get current time
TIME=$(date '+%H:%M:%S')
DATE=$(date '+%a %b %d')
# Get battery info if available
BATTERY=""
if [ -f /sys/class/power_supply/BAT*/capacity ]; then
BAT_LEVEL=$(cat /sys/class/power_supply/BAT*/capacity 2>/dev/null | head -1)
BAT_STATUS=$(cat /sys/class/power_supply/BAT*/status 2>/dev/null | head -1)
if [ -n "$BAT_LEVEL" ]; then
case "$BAT_STATUS" in
"Charging") BAT_ICON="🔌" ;;
"Discharging") BAT_ICON="🔋" ;;
"Full") BAT_ICON="🔋" ;;
*) BAT_ICON="🔋" ;;
esac
BATTERY=" ${BAT_ICON}${BAT_LEVEL}%"
fi
fi
# Get CPU usage
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}' 2>/dev/null || echo "")
if [ -n "$CPU_USAGE" ]; then
CPU=" 💻${CPU_USAGE}"
else
CPU=""
fi
# Get memory usage
MEM_INFO=$(free | grep Mem)
if [ -n "$MEM_INFO" ]; then
MEM_USED=$(echo $MEM_INFO | awk '{printf "%.1f", $3/1024/1024}')
MEM_TOTAL=$(echo $MEM_INFO | awk '{printf "%.1f", $2/1024/1024}')
MEMORY=" 🧠${MEM_USED}/${MEM_TOTAL}GB"
else
MEMORY=""
fi
# Combine status
STATUS="${BATTERY}${CPU}${MEMORY} 📅 ${DATE} 🕒 ${TIME}"
# Send to dwlb for all outputs
for output in $(get_outputs); do
dwlb -status "$output" "$STATUS" 2>/dev/null
done
# Update every 5 seconds
sleep 5
done