41 lines
971 B
Bash
Executable File
41 lines
971 B
Bash
Executable File
#!/bin/bash
|
|
|
|
[[ ${BLOCK_INSTANCE} == '' ]] && BATTERY=0 || BATTERY=${BLOCK_INSTANCE}
|
|
cat /sys/class/power_supply/BAT${BATTERY}/uevent | gawk -F '=' '
|
|
/POWER_SUPPLY_STATUS=/ {
|
|
status=$2
|
|
}
|
|
/POWER_SUPPLY_ENERGY_FULL=/ {
|
|
efull=$2
|
|
}
|
|
/POWER_SUPPLY_ENERGY_NOW=/ {
|
|
enow=$2
|
|
}
|
|
END {
|
|
charge=enow/efull*100
|
|
if (status == "Discharging") {
|
|
status="↓"
|
|
} else if (status == "Charging") {
|
|
status="↑"
|
|
} else {
|
|
status=""
|
|
}
|
|
printf("%s%d%", status, charge)
|
|
print("\n")
|
|
if (charge < 20) {
|
|
print("#FF0000\n")
|
|
} else if (charge < 40) {
|
|
print("#FFAE00\n")
|
|
} else if (charge < 60) {
|
|
print("#FFF600\n")
|
|
} else if (charge < 85) {
|
|
print("#A8FF00\n")
|
|
} else {
|
|
print("#04B431\n")
|
|
}
|
|
if (charge < 5) {
|
|
exit 33
|
|
}
|
|
}
|
|
'
|