]> permondes.de Git - TermuxBatteryStatus.git/blob - batterie-status.scr
First Documentation
[TermuxBatteryStatus.git] / batterie-status.scr
1 #!/bin/sh
2
3 # On Android devices with Termux, notify the user when the device is charged to 80%
4
5 # set -x
6
7 # get the battery status and generate variables out of the returned jason data
8 # then analyse the response
9 # terminate loop when device is not charging or reached >79%
10 while [ true ]
11 do
12 eval "$( \
13 termux-battery-status | \
14 jq -r 'to_entries | .[] | map_values(tostring) | .key + "=\"" + .value + "\"" ' )"
15 if [ "$status" != "CHARGING" ]
16 then break
17 elif [ $percentage -gt 79 ]
18 then break
19 fi
20 sleep 5m
21 done
22
23 # vibrate shortly, show details in the notification area
24 termux-notification --id bs --title "Termux Battery-Status" --vibrate 200 \
25 -c "$(date +"%e.%m.%Y %k:%M:%S"): $status, $plugged, $percentage%, $health health, $temperature °C"
26
27 # tell status and percentage in english, slightly slower speed than standard
28 termux-tts-speak -l en -r 0.95 "$status, $plugged, $percentage%"
29
30 exit
31
32 # jq
33 # -r : output not in json format, raw
34 # to_entries: converts an object to an array of key-value pairs.
35 # .[] : returns all of the elements of an array
36 # map_values(tostring) : convert numbers to strings, needed for the + later-on
37 # .key=.value : generate the variable assignment