--- /dev/null
+#!/bin/sh
+# Stefan Huber, 2024-11-10
+
+acpi=$(acpi)
+date=$(date -Iseconds --utc)
+addendum=""
+
+if [ "$1" = "post" ]; then
+ lastpre=$(grep pre /var/log/batterstat.log | tail -n1)
+
+ if [ ! -z "${lastpre}" ]; then
+ preprecent=$(echo "${lastpre}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }')
+ predate=$(echo "${lastpre}" | grep -o " at .*" | awk '{ print $2 }')
+
+ postpercent=$(echo "${acpi}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }')
+
+ let diffmin=($(date +%s -d ${date})-$(date +%s -d ${predate}))/60
+ let diffperc=(prepercent-postprecent)
+
+ addendum=", discharged ${diffperc}% (${preprecent}% -> ${postpercent}%) in ${diffmin} minutes"
+ fi
+fi
+
+echo "$1: ${acpi} at ${date}${addendum}" >> /var/log/batterstat.log