summaryrefslogtreecommitdiff
path: root/bin/status.sh
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-04-28 02:30:33 +0100
committerubq323 <ubq323@ubq323.website>2023-04-28 02:30:33 +0100
commit6e3a1f376fbef9d0f6f8c72d6b22ff1d40e812ed (patch)
tree10829dd8d7c7125d511c270ba392e5c5812114d8 /bin/status.sh
parent4762791fad362c8afe1c9a2b1c555c6a8d7b79d1 (diff)
movement
Diffstat (limited to 'bin/status.sh')
-rwxr-xr-xbin/status.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/bin/status.sh b/bin/status.sh
new file mode 100755
index 0000000..5bd9e4c
--- /dev/null
+++ b/bin/status.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+puts () {
+ printf %s "$1"
+}
+
+escape () {
+ printf %s "$1" | sed -e 's*\\*\\\\*g' -e 's!"!\\"!g'
+}
+
+block_basic () {
+ printf '{"full_text":"%s"},' "$1"
+}
+block_color () {
+ printf '{"full_text":"%s","color":"%s"},' "$1" "$2"
+}
+
+BDIR=/sys/class/power_supply/BAT0
+
+# header
+printf '%s\n' '{"version":1}'
+puts '['
+
+while true; do
+ puts '['
+
+ volinfo="$(amixer get Master | grep 'Mono:')"
+ vol_level="$(printf %s "$volinfo" | awk -F'[][]' '{print $2}')"
+ vol_enabled="$(printf %s "$volinfo" | awk -F'[][]' '{print $6}')"
+ color="#ffffff"; bl=""; br=""
+ [ "$vol_enabled" = "off" ] && { color="#ffff00"; bl="("; br=")"; }
+ block_color "vol $bl$vol_level$br" "$color"
+
+ bat_status="$(cat $BDIR/status | tr 'a-z' 'A-Z' | head -c 3)"
+ bat_level="$(cat $BDIR/capacity)"
+ color="#ffffff"
+ if [ "$bat_level" -le 10 ]; then
+ color="#ff0000"
+ elif [ "$bat_level" -le 25 ]; then
+ color="#ffff00"
+ fi
+ block_color "$bat_status $bat_level%" "$color"
+
+ date="$(date +'%a %Y-%m-%d %H:%M:%S')"
+ block_basic "$date"
+
+
+ puts '],'
+ sleep 1
+
+done
+