summaryrefslogtreecommitdiff
path: root/i3blocks-battery.sh
diff options
context:
space:
mode:
authorAdam Carpenter <atc@53hor.net>2020-05-10 21:13:46 -0400
committerAdam Carpenter <atc@53hor.net>2020-05-10 21:13:46 -0400
commitb184782970853b3c479f6c4ad833a36a3aea7afa (patch)
tree318233a807c61414a2696b5300adf3cec6e700e5 /i3blocks-battery.sh
downloadscripts-b184782970853b3c479f6c4ad833a36a3aea7afa.tar.xz
scripts-b184782970853b3c479f6c4ad833a36a3aea7afa.zip
mega update
Diffstat (limited to 'i3blocks-battery.sh')
-rwxr-xr-xi3blocks-battery.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/i3blocks-battery.sh b/i3blocks-battery.sh
new file mode 100755
index 0000000..33e6a74
--- /dev/null
+++ b/i3blocks-battery.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+base="/sys/class/power_supply/BAT0/"
+low=25
+med=50
+high=75
+icon_charging_high=󱊦
+icon_charging_low=󱊤
+icon_charging_med=󱊥
+icon_charging_dry=󰢟
+icon_high=󱊣
+icon_low=󱊡
+icon_med=󱊢
+icon_dry=󰂎
+
+full=$(< $base/energy_full_design)
+now=$(< $base/energy_now)
+stat=$(< $base/status)
+percent=$(echo "result = $now / $full * 100; scale=0; result / 1" | bc -l)
+
+if [ "$stat" = "Discharging" ]; then
+ [ $percent -lt $low ] && printf $icon_dry
+ [ $percent -ge $low ] && [ $percent -lt $med ] && printf $icon_low
+ [ $percent -ge $med ] && [ $percent -lt $high ] && printf $icon_med
+ [ $percent -ge $high ] && printf $icon_high
+else
+ [ $percent -lt $low ] && printf $icon_charging_dry
+ [ $percent -ge $low ] && [ $percent -lt $med ] && printf $icon_charging_low
+ [ $percent -ge $med ] && [ $percent -lt $high ] && printf $icon_charging_med
+ [ $percent -ge $high ] && printf $icon_charging_high
+fi
+
+printf " %s%%\n" $percent