Skip to content

Instantly share code, notes, and snippets.

@LeoniePhiline
Last active June 17, 2023 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeoniePhiline/2277585f74fbe089a2f00fe3b0e80195 to your computer and use it in GitHub Desktop.
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.
#!/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