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

View File

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