dotfiles/.local/scripts/battery-notify.sh

17 lines
456 B
Bash
Executable File

#!/bin/bash
BATTERY_LEVEL=$(upower -i $(upower -e | grep 'BAT') | grep -E "percentage" | awk '{print $2}' | sed 's/%//')
AC_POWER=$(cat /sys/class/power_supply/AC0/online)
if [ $AC_POWER -eq 1 ]; then
exit
fi
if [ $BATTERY_LEVEL -le 5 ]; then
notify-send "Low Battery" "Battery level is ${BATTERY_LEVEL}%" -u critical
exit
fi
if [ $BATTERY_LEVEL -le 10 ]; then
notify-send "Low Battery" "Battery level is ${BATTERY_LEVEL}%" -u normal
fi