From 90c27d673eb8d56974555ac9a3b2f842cc5a3b3a Mon Sep 17 00:00:00 2001 From: Permondes Date: Mon, 16 Nov 2020 21:00:58 +0100 Subject: [PATCH] Initial Release --- batterie-status.scr | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 batterie-status.scr 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 -- 2.39.2