waybar: add mouse baterry indicator

This commit is contained in:
Leonardo Eugênio 2025-09-01 01:09:19 -03:00
parent 910670ba0b
commit b8cd22e425
7 changed files with 96 additions and 24 deletions

39
scripts/mouse-battery Executable file
View file

@ -0,0 +1,39 @@
#!/bin/sh
set -e
MODEL_NAME_FILE=$(rg --files-with-matches G502 /sys/class/power_supply/*/model_name | head -n1)
if test -z "$MODEL_NAME_FILE"; then
echo
exit 0
fi
MOUSE=$(dirname "$MODEL_NAME_FILE")
if test -z "$MOUSE"; then
echo
exit 0
fi
CAPACITY=$(cat "$MOUSE/capacity")
STATUS=$(cat "$MOUSE/status")
echo -n '🖱️'
if test "$STATUS" = "Charging"; then
echo -n "󰂄"
else
print-battery-icon "$CAPACITY"
fi
if test "$CAPACITY" -lt 50; then
echo -n "$CAPACITY%"
fi
echo
# Tooltip
echo -n '🖱️'
print-battery-icon "$CAPACITY"
echo " $CAPACITY%"