Files
dotfiles/.config/polybar/scripts/battery.sh
druckdev b1d396babd *: Use /usr/bin/env in shebangs for bash & zsh
To increase the portability (OSX for example has zsh under `/bin/zsh`).
2021-07-14 13:48:21 +02:00

30 lines
724 B
Bash
Executable File

#!/usr/bin/env bash
## config
full=80
low=20
############################
red='%{F#f00}'
green='%{F#0f0}'
end='%{F-}'
bat="$(cat /sys/class/power_supply/BAT0/capacity)"
ac="$(cat /sys/class/power_supply/AC/online)"
declare -a ramp
ramp=(          )
# display in red when under $low and no charger is connected
[[ "$bat" -gt "$low" || "$ac" -eq 1 ]] || color="$red"
# display in green when over $full and a charger is connected
[[ "$bat" -lt "$full" || "$ac" -eq 0 ]] || color="$green"
let "icon_index = $bat / (${#ramp[@]} - 1)"
[[ $icon_index -lt ${#ramp[@]} ]] || icond_index=10
icon="${ramp[$icon_index]}"
[[ "$ac" -eq 0 ]] || charge=""
echo "${color}${icon}${charge} ${bat}%"