+#!/bin/sh
+
+# On Android devices with Termux, notify the user when the device is charged to 80%
+
+# set -x
+
+# get the battery status and generate variables out of the returned jason data
+# then analyse the response
+# terminate loop when device is not charging or reached >79%
+while [ true ]
+do
+ eval "$( \
+ termux-battery-status | \
+ jq -r 'to_entries | .[] | map_values(tostring) | .key + "=\"" + .value + "\"" ' )"
+ if [ "$status" != "CHARGING" ]
+ then break
+ elif [ $percentage -gt 79 ]
+ then break
+ fi
+ sleep 5m
+done
+
+# vibrate shortly, show details in the notification area
+termux-notification --id bs --title "Termux Battery-Status" --vibrate 200 \
+ -c "$(date +"%e.%m.%Y %k:%M:%S"): $status, $plugged, $percentage%, $health health, $temperature °C"
+
+# tell status and percentage in english, slightly slower speed than standard
+termux-tts-speak -l en -r 0.95 "$status, $plugged, $percentage%"
+
+exit
+
+# jq
+# -r : output not in json format, raw
+# to_entries: converts an object to an array of key-value pairs.
+# .[] : returns all of the elements of an array
+# map_values(tostring) : convert numbers to strings, needed for the + later-on
+# .key=.value : generate the variable assignment