mine-hyprdots/bin/battery-charging.sh

22 lines
801 B
Bash
Raw Normal View History

2024-09-15 12:31:53 +05:30
#!/bin/sh
# Send a notification when the laptop is plugged in/unplugged
# Add the following to /etc/udev/rules.d/60-power.rules (replace USERNAME with your user)
export XAUTHORITY=~/.Xauthority
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
BATTERY_STATE=$1
BATTERY_LEVEL=$(acpi -b | grep "Battery 0" | grep -P -o '[0-9]+(?=%)')
# My battery takes a couple of seconds to recognize as charging, so this is a hacky way to deal with it
case "$BATTERY_STATE" in
"charging") BATTERY_CHARGING="Charging" ; BATTERY_ICON="charging" ;;
"discharging") BATTERY_CHARGING="Discharging" ; BATTERY_ICON="discharging" ;;
esac
# Send notification
notify-send "${BATTERY_CHARGING}" "${BATTERY_LEVEL}% of battery charged." -u normal -i "battery-${BATTERY_ICON}" -t 5000 -r 9991