mirror of
https://github.com/basecamp/omarchy.git
synced 2025-07-27 04:09:23 +00:00
33 lines
941 B
Bash
Executable File
33 lines
941 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Omarchy Battery Monitor
|
|
# One-shot script that checks battery and sends notification if needed
|
|
# Designed to be run by systemd timer every 30 seconds
|
|
|
|
BATTERY_THRESHOLD=10
|
|
NOTIFICATION_FLAG="/run/user/$UID/omarchy_battery_notified"
|
|
|
|
get_battery_percentage() {
|
|
upower -i $(upower -e | grep 'BAT') | grep -E "percentage" | grep -o '[0-9]\+%' | sed 's/%//'
|
|
}
|
|
|
|
get_battery_state() {
|
|
upower -i $(upower -e | grep 'BAT') | grep -E "state" | awk '{print $2}'
|
|
}
|
|
|
|
send_notification() {
|
|
notify-send -u critical "Battery Low" "Battery level is at ${1}%! Please plug in your charger." -i battery-caution
|
|
}
|
|
|
|
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
|