Skip to content

Instantly share code, notes, and snippets.

@adrian-green
Created March 30, 2026 04:07
Show Gist options
  • Select an option

  • Save adrian-green/79dda0e6a6b808f9743c143f20f1be95 to your computer and use it in GitHub Desktop.

Select an option

Save adrian-green/79dda0e6a6b808f9743c143f20f1be95 to your computer and use it in GitHub Desktop.
Linux user service - Battery Power
#!/bin/bash
# bat: https://github.com/tshakalekholoane/bat
# --- Variables ---
WARNING_THRESHOLD=35 # The percentage at which to warn you
CHECK_INTERVAL=60 # How often to check (in seconds)
POPUP_DURATION=15 # How long the popup stays on screen (in seconds)
while true; do
STATUS=$(bat status)
# Guard clause: Exit if charging
if [ "$STATUS" = "Charging" ]; then
sleep "$CHECK_INTERVAL"
continue
fi
# If we made it here, we are discharging. Now check capacity.
CAPACITY=$(bat capacity)
# Validate capacity is a number, then check against threshold
if [[ "$CAPACITY" =~ ^[0-9]+$ ]] && [ "$CAPACITY" -le "$WARNING_THRESHOLD" ]; then
kdialog --passivepopup "🪫 Battery is ${CAPACITY}%, plugin in charger now" "$POPUP_DURATION" --title "Battery Low"
fi
# Wait before checking again
sleep "$CHECK_INTERVAL"
done
@adrian-green
Copy link
Copy Markdown
Author

KDE, obviously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment