summary refs log tree commit diff
path: root/bin/lowbat
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2020-01-26 17:16:07 +0100
committerRobert Günzler <r@gnzler.io>2020-01-26 18:00:59 +0100
commitf5d56602df70950de6b7d40966b00c9939c81763 (patch)
treeb50ffeb5496fe3525cc1bab2629389ced95435b7 /bin/lowbat
Intial commit of v2
See https://drewdevault.com/2019/12/30/dotfiles.html
Diffstat (limited to 'bin/lowbat')
-rwxr-xr-xbin/lowbat19
1 files changed, 19 insertions, 0 deletions
diff --git a/bin/lowbat b/bin/lowbat
new file mode 100755
index 0000000..90702a1
--- /dev/null
+++ b/bin/lowbat
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+set -e
+
+acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
+	read -r status capacity
+
+	if [[ $status -eq "Discharging" ]]; then
+		if [[ $capacity -lt 10 ]]; then
+			echo "battery capacity: $capacity"
+			notify-send "battery low" "System will hibernate at 5%"
+		fi
+		if [[ $capacity -lt 5 ]]; then
+			echo "hibernating"
+			notify-send "battery low" "System will hibernate now"
+			systemctl hibernate
+		fi
+	fi
+}