Rewrite to use acpi and show remaining time
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
20d45a6232
commit
9855a42ae9
1 changed files with 14 additions and 6 deletions
|
@ -1,22 +1,30 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
|
||||||
ac_conn=0
|
ac_conn=0
|
||||||
for ac in $(find /sys/class/power_supply -type l -name 'A*'); do
|
(acpi -a | grep -q on-line) && ac_conn=1
|
||||||
[ $(cat "${ac}/online") -eq 1 ] && ac_conn=1
|
|
||||||
done
|
|
||||||
|
|
||||||
bat_cap=()
|
bat_cap=()
|
||||||
for bat in $(find /sys/class/power_supply -type l -name 'B*'); do
|
for line in $(acpi -b | grep -v 'unavailable' | sed -E 's/.*: ([^,]+), ([0-9]+)%(, ([0-9]+:[0-9]+|)|).*/\1\t\2\t\4/'); do
|
||||||
color='#ffffff'
|
color='#ffffff'
|
||||||
cap=$(cat "${bat}/capacity")
|
|
||||||
|
state=$(echo "${line}" | cut -d $'\t' -f 1)
|
||||||
|
cap=$(echo "${line}" | cut -d $'\t' -f 2)
|
||||||
|
remain="($(echo "${line}" | cut -d $'\t' -f 3)) "
|
||||||
|
|
||||||
|
[[ ${state} == 'Full' ]] && remain=''
|
||||||
|
[[ ${remain} == '() ' ]] && remain='(??) '
|
||||||
|
|
||||||
[ ${cap} -lt 50 ] && color='#ffd966'
|
[ ${cap} -lt 50 ] && color='#ffd966'
|
||||||
[ ${cap} -lt 25 ] && color='#dd0000'
|
[ ${cap} -lt 25 ] && color='#dd0000'
|
||||||
|
|
||||||
bat_cap+=("<span color=\"${color}\">${cap}%</span>")
|
bat_cap+=("<span color=\"${color}\">${cap}% ${remain}</span>")
|
||||||
done
|
done
|
||||||
|
|
||||||
|
IFS=' '
|
||||||
|
|
||||||
if [ ${ac_conn} -eq 0 ]; then
|
if [ ${ac_conn} -eq 0 ]; then
|
||||||
printf '\uf58d %s' "${bat_cap[*]}"
|
printf '\uf58d %s' "${bat_cap[*]}"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue