cfg/.config/i3blocks/battery
Knut Ahlers 4ae353dc51
Bring more color to the i3bar
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-12-03 15:22:12 +01:00

24 lines
530 B
Bash
Executable file

#!/bin/bash
set -euo pipefail
ac_conn=0
for ac in $(find /sys/class/power_supply -type l -name 'A*'); do
[ $(cat "${ac}/online") -eq 1 ] && ac_conn=1
done
bat_cap=()
for bat in $(find /sys/class/power_supply -type l -name 'B*'); do
color='#ffffff'
cap=$(cat "${bat}/capacity")
[ ${cap} -lt 50 ] && color='#ffd966'
[ ${cap} -lt 25 ] && color='#dd0000'
bat_cap+=("<span color=\"${color}\">${cap}%</span>")
done
if [ ${ac_conn} -eq 0 ]; then
printf '\uf58d %s' "${bat_cap[*]}"
else
printf '\uf740 %s' "${bat_cap[*]}"
fi