summaryrefslogtreecommitdiff
path: root/battery
diff options
context:
space:
mode:
authortslil clingman <>2019-01-20 23:04:07 -0500
committertslil clingman <>2019-01-20 23:04:07 -0500
commitd8fae3962161863441ac632ef7b29bb6d3e98854 (patch)
tree3f06c97b33ab3c50fe4912537178f460067bedec /battery
parentf92c2d7834ce029a8b1a5f199296cba5e59342aa (diff)
More portable script
Diffstat (limited to 'battery')
-rwxr-xr-xbattery35
1 files changed, 31 insertions, 4 deletions
diff --git a/battery b/battery
index ef3997e..51464a5 100755
--- a/battery
+++ b/battery
@@ -1,6 +1,33 @@
-#!/usr/bin/env sh
+#!/bin/sh
-# Quick hack to display battery levels for the laptop
+names="sbs-20-000b BAT0 BAT1"
+dir=""
-str="s/ Charging, /C/;s/ Discharging, /D/;s/ Unknown,/U/;s/ Full, /F/"
-acpi | cut -d: -f 2- | sed "$str" | cut -d\ -f 1-2 | cut -d: -f 1-2;
+for n in $names; do
+ if [ -d "/sys/class/power_supply/$n" ] ; then
+ dir=$n
+ break
+ fi;
+done
+
+fetch() {
+ cat /sys/class/power_supply/$dir/$1
+}
+
+status=$(fetch status)
+
+if [ "$status" = "Full" ] ; then
+ echo $status
+else
+
+ if [ "$status" = "Discharging" ]; then
+ time=$(fetch time_to_empty_avg)
+ else
+ time=$(fetch time_to_full_avg)
+ fi;
+
+ hours=$(($time/3600))
+ minutes=$(($time/60-$hours*60))
+
+ echo $status $(fetch capacity)%, "$hours"h "$minutes"m
+fi;