Last active
June 17, 2023 16:52
-
-
Save LeoniePhiline/2277585f74fbe089a2f00fe3b0e80195 to your computer and use it in GitHub Desktop.
OpenSUSE Tumbleweed laptop battery care warnings, below 20% when discharging and above 80% when charging. Requires ripgrep for regex matching. Run as KDE autostart-script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/zsh | |
sleep 30 | |
while true | |
do | |
# You might need to change the `Battery $N` number in both regular expressions below. | |
# Use `acpi -b` to determine the battery number you want to watch. | |
state="$(acpi -b | rg '^Battery 1: (\w+)' --only-matching --replace '$1')" | |
percentage="$(acpi -b | rg '^Battery 1: \w+, (\d+)%' --only-matching --replace '$1')" | |
intro="Battery care check:" | |
title="Battery $state" | |
body="Level: ${percentage}%" | |
if [[ $state = "Charging" || $state = "Full" ]]; then | |
if [[ $percentage -ge 80 ]]; then | |
echo "[ WARN ] $intro $title - $body" | |
notify-send --urgency=CRITICAL "$title" "$body" | |
paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga | |
else | |
echo "[ OK ] $intro $title - $body" | |
fi | |
else | |
if [[ $percentage -le 20 ]]; then | |
echo "[ WARN ] $intro $title - $body" | |
notify-send --urgency=CRITICAL "$title" "$body" | |
paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga | |
else | |
echo "[ OK ] $intro $title - $body" | |
fi | |
fi | |
# 2m30s | |
sleep 150 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment