From 64b3cc9b3341e1c067bda183809035efa24e11a5 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Mon, 7 Feb 2022 23:00:16 -0300 Subject: [PATCH] Add battery.sh --- blocks.def/battery.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 blocks.def/battery.sh diff --git a/blocks.def/battery.sh b/blocks.def/battery.sh new file mode 100755 index 0000000..2701b56 --- /dev/null +++ b/blocks.def/battery.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +battery=/sys/class/power_supply/BAT0 + +case "$(cat "$battery/status" 2>&1)" in + "Full") status="⚡" ;; + "Discharging") status="🔋" ;; + "Charging") status="🔌" ;; + "Not charging") status="🛑" ;; + "Unknown") status="♻️" ;; + *) exit 1 ;; +esac + +capacity="$(cat "$battery/capacity" 2>&1)" +capacity=$(echo "$capacity/88*100" | bc -l) + +printf "%s %.0f%%" "$status" "$capacity"