diff options
Diffstat (limited to 'basics/.local/bin/statusbar/battery')
| -rwxr-xr-x | basics/.local/bin/statusbar/battery | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/basics/.local/bin/statusbar/battery b/basics/.local/bin/statusbar/battery new file mode 100755 index 0000000..da6dd12 --- /dev/null +++ b/basics/.local/bin/statusbar/battery @@ -0,0 +1,30 @@ +#!/bin/sh + +battery_path='/sys/class/power_supply/BAT0' + +percentage=$(head -n1 "${battery_path}/capacity") +state=$(head -n1 "${battery_path}/status") +rate=$([ -f "${battery_path}/current_now" ] && + head -n1 "${battery_path}/current_now" || + head -n1 "${battery_path}/power_now") +volt=$(head -n1 "${battery_path}/voltage_now") +now=$([ -f "${battery_path}/charge_now" ] && + head -n1 "${battery_path}/charge_now" || + head -n1 "${battery_path}/energy_now") +max=$([ -f "${battery_path}/current_full" ] && + head -n1 "${battery_path}/current_full" || + head -n1 "${battery_path}/energy_full") +cap=$([ "$state" = "Charging" ] && + echo "$max $now" | awk '{printf "%d", $1 - $2}' || + echo "$now") + +remaining=$( echo "$cap $volt" | awk '{printf "%f", $1/$2}' ) +current_rate=$( echo "$rate $volt" | awk '{printf "%f", $1/$2}' ) +seconds_remaining=$( [ "${current_rate#0.00}" = "$current_rate" ] && + echo "$remaining $current_rate" | + awk '{printf "%d", 3600*$1/$2}' || + echo "0" ) +time_remaining=$( date -ud "@${seconds_remaining}" "+%H:%M:%S" ) + +# TODO: more variable output with flags? +echo "$state $percentage $time_remaining" |
