This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/bat_notify

38 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env sh
######################################################################
# @author : swytch
# @file : bat_notify
# @license : MIT
# @created : Wednesday May 20, 2020 17:54:08 CEST
#
# @description : send a notification with charge level
######################################################################
notify() { \
for x in /sys/class/power_supply/BAT?/capacity;
do
case "$(cat "$x")" in
1[0-9]) notify-send -u "normal" "Battery is running low ($(cat "$x")%)" "Please plug your computer to a power source" ;;
[0-9]) notify-send -u "critical" "Battery is dangerously low ($(cat "$x")%)" "Please plug your computer to a power source - <b>NOW!</b>" ;;
esac
done
}
update() { \
# We want the notification to be sent every 5 mins
# But only if the computer is unplugged
if [ "$(cat /sys/class/power_supply/AC/online)" = 0 ]; then
notify && refbar
fi
wait
}
while :; do
update
# Sleep for 5 minutes before sending another notification
sleep 300 &
wait
done