From: Permondes Date: Mon, 16 Nov 2020 20:00:58 +0000 (+0100) Subject: Initial Release X-Git-Url: https://permondes.de/gitweb/TermuxBatteryStatus.git/commitdiff_plain/90c27d673eb8d56974555ac9a3b2f842cc5a3b3a?ds=sidebyside Initial Release --- 90c27d673eb8d56974555ac9a3b2f842cc5a3b3a diff --git a/batterie-status.scr b/batterie-status.scr new file mode 100644 index 0000000..b27c88a --- /dev/null +++ b/batterie-status.scr @@ -0,0 +1,37 @@ +#!/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