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"