Created
March 30, 2026 04:07
-
-
Save adrian-green/79dda0e6a6b808f9743c143f20f1be95 to your computer and use it in GitHub Desktop.
Linux user service - Battery Power
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
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
KDE, obviously.