diff options
| author | tslil clingman <> | 2019-01-20 23:04:07 -0500 |
|---|---|---|
| committer | tslil clingman <> | 2019-01-20 23:04:07 -0500 |
| commit | d8fae3962161863441ac632ef7b29bb6d3e98854 (patch) | |
| tree | 3f06c97b33ab3c50fe4912537178f460067bedec /battery | |
| parent | f92c2d7834ce029a8b1a5f199296cba5e59342aa (diff) | |
More portable script
Diffstat (limited to 'battery')
| -rwxr-xr-x | battery | 35 |
1 files changed, 31 insertions, 4 deletions
@@ -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; |
