Add battery.sh

This commit is contained in:
Santiago Lo Coco 2022-02-07 23:00:16 -03:00
parent 0cda6acf7e
commit 64b3cc9b33
1 changed files with 17 additions and 0 deletions

17
blocks.def/battery.sh Executable file
View File

@ -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"