add bar support per default for module battery

This commit is contained in:
koksnuss 2018-05-27 00:51:18 +02:00
parent 05bc0370b0
commit 33dd3a4168
2 changed files with 32 additions and 10 deletions

6
config
View File

@ -38,15 +38,15 @@ label=⎋
# /sys/class/power_supply/BATx you can use the instance=x command
[battery]
# label=battery
# label=
# label=~
# ▁▂▃▄▅▆▇█
# █
# ▉
# ▊
# ▋
# ▌
# ▍⎋
# ▎⌨
# ▍⎋
# ▎⌨
# ▏⟠, ⟰, ⟱, ⟲, ⟳, ⤋, ⤊,
# [battery]
# instance=1

View File

@ -2,6 +2,8 @@
DIR="/sys/class/power_supply"
[[ "$BLOCK_BUTTON" == "1" ]] && LONG=true || LONG=false
if [[ "$BLOCK_INSTANCE" == "" ]]; then
for BAT in $DIR/BAT*/; do
[[ -f "${BAT}uevent" ]] && BATS+="$BAT/uevent "
@ -16,7 +18,7 @@ if [[ "$BATS" == "" ]]; then
exit 33
fi
cat $BATS | gawk -F '=' '
cat $BATS | gawk -F '=' -v LONG="$LONG" '
BEGIN {
efull = 0
enow = 0
@ -24,13 +26,10 @@ cat $BATS | gawk -F '=' '
}
/POWER_SUPPLY_STATUS=/ {
if (status == "") {
status = $2
if (status == "Discharging") {
if ($2 == "Discharging") {
status = ""
} else if (status == "Charging") {
} else if ($2 == "Charging") {
status = "⚡"
} else {
status = ""
}
}
}
@ -42,7 +41,30 @@ cat $BATS | gawk -F '=' '
}
END {
charge = enow / efull * 100
if (LONG == "false") {
if (charge < 100 / 9) {
printf("\n")
} else if (charge < 100 / 9 * 2 ) {
printf("%s▁\n", status)
} else if (charge < 100 / 9 * 3 ) {
printf("%s▂\n", status)
} else if (charge < 100 / 9 * 4 ) {
printf("%s▃\n", status)
} else if (charge < 100 / 9 * 5 ) {
printf("%s▄\n", status)
} else if (charge < 100 / 9 * 6 ) {
printf("%s▅\n", status)
} else if (charge < 100 / 9 * 7 ) {
printf("%s▆\n", status)
} else if (charge < 100 / 9 * 8 ) {
printf("%s▇\n", status)
} else {
printf("%s█\n", status)
}
} else {
printf("%s%d%\n", status, charge)
}
printf("%s%d\n", status, charge)
if (charge > 25) {
print("#04B431\n")