summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.net>2022-01-26 20:38:39 -0500
committertslil clingman <tslil@posteo.net>2022-01-26 20:38:39 -0500
commit69e3dfc6d689342841fe5be8afc483b7171fd94a (patch)
treea69b4a2d982f1234dbab83bf8b6dcc70d01c60e3
parent7ccd2d5b3d14b528e9d497e7937c31215568d338 (diff)
Rewrote battery to use /sys
-rwxr-xr-xbattery22
1 files changed, 17 insertions, 5 deletions
diff --git a/battery b/battery
index 1e7a7da..250f81f 100755
--- a/battery
+++ b/battery
@@ -1,7 +1,19 @@
#!/bin/sh
-report=$(acpi | tr -d ',')
-status=$(echo $report | cut -d\ -f 3 | cut -b 1)
-perc=$(echo $report | cut -d\ -f 4)
-time=$(echo $report | cut -d\ -f 5 | sed 's/\([0-9]*\):\([0-9]*\).*/\1h\2m/')
-echo $status$perc $time
+awk 'BEGIN { status = ""; efull = 0; enow = 1; pnow = 1; FS="="; }
+/POWER_SUPPLY_STATUS/ { status = $2; }
+/POWER_SUPPLY_ENERGY_FULL=/ { efull = $2; }
+/POWER_SUPPLY_ENERGY_NOW/ { enow = $2; }
+/POWER_SUPPLY_POWER_NOW/ { pnow = $2; }
+END { if (status=="Full"||status=="Unknown") {
+ print status
+ } else {
+ h=enow/pnow;
+ m=(h-int(h))*60;
+ printf("%s%d%% %dh%dm\n",
+ substr(status, 0, 1),
+ enow/efull*100.0,
+ h, m);
+ }
+ }' \
+ /sys/class/power_supply/BAT0/uevent