diff options
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; |
