dev: automated commit - 2025-09-29 15:58:41
This commit is contained in:
parent
32748f21c8
commit
e1a5203154
1 changed files with 36 additions and 0 deletions
36
local-bin/.local/bin/battery-monitor
Executable file
36
local-bin/.local/bin/battery-monitor
Executable file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Designed to be run by systemd timer every 30 seconds and alerts if battery is low
|
||||||
|
|
||||||
|
BATTERY_THRESHOLD=10
|
||||||
|
NOTIFICATION_FLAG="/run/user/$UID/omarchy_battery_notified"
|
||||||
|
|
||||||
|
get_battery_percentage() {
|
||||||
|
upower -i "$(upower -e | grep 'BAT')" |
|
||||||
|
awk -F: '/percentage/ {
|
||||||
|
gsub(/[%[:space:]]/, "", $2);
|
||||||
|
val=$2;
|
||||||
|
printf("%d\n", (val+0.5))
|
||||||
|
exit
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_battery_state() {
|
||||||
|
upower -i $(upower -e | grep 'BAT') | grep -E "state" | awk '{print $2}'
|
||||||
|
}
|
||||||
|
|
||||||
|
send_notification() {
|
||||||
|
notify-send -u critical " Time to recharge!" "Battery is down to ${1}%" -i battery-caution -t 30000
|
||||||
|
}
|
||||||
|
|
||||||
|
BATTERY_LEVEL=$(get_battery_percentage)
|
||||||
|
BATTERY_STATE=$(get_battery_state)
|
||||||
|
|
||||||
|
if [[ "$BATTERY_STATE" == "discharging" && "$BATTERY_LEVEL" -le "$BATTERY_THRESHOLD" ]]; then
|
||||||
|
if [[ ! -f "$NOTIFICATION_FLAG" ]]; then
|
||||||
|
send_notification "$BATTERY_LEVEL"
|
||||||
|
touch "$NOTIFICATION_FLAG"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
rm -f "$NOTIFICATION_FLAG"
|
||||||
|
fi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue