summaryrefslogtreecommitdiff
path: root/batterylow
diff options
context:
space:
mode:
Diffstat (limited to 'batterylow')
-rwxr-xr-xbatterylow19
1 files changed, 13 insertions, 6 deletions
diff --git a/batterylow b/batterylow
index 2086cb2..0f2ebd4 100755
--- a/batterylow
+++ b/batterylow
@@ -1,15 +1,22 @@
#!/bin/sh
-# This script sends notifications when battery is low.
+# This script sends notifications when battery is low,
+# but only while discharging.
-# those variables may be unnecessary
-export DISPLAY=:0
-export HOME=/home/filipek
+battery=$(upower -e | grep BAT | head -n 1)
-percentage=$(upower -i "$(upower -e | grep BAT)" |
+percentage=$(upower -i "$battery" |
awk '/percentage/ {gsub(/%/, "", $2); print $2}')
+state=$(upower -i "$battery" |
+ awk '/state/ {print $2}')
+
+# Only notify if the battery is discharging
+if [ "$state" != "discharging" ]; then
+ exit 0
+fi
+
if [ "$percentage" -le 5 ]; then
notify-send "Battery very low."
-elif [ "$percentage" -ge 14 ] && [ "$percentage" -le 15 ]; then
+elif [ "$percentage" -le 15 ]; then
notify-send "Battery low."
fi