46 lines
1.1 KiB
Bash
Executable File
46 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
[[ ${BLOCK_INSTANCE} == '' ]] && BAT=0 || BAT=${BLOCK_INSTANCE}
|
|
DIR="/sys/class/power_supply/BAT"
|
|
if [ ! -f "${DIR}${BAT}/uevent" ]; then
|
|
echo " not found "
|
|
echo "n/a"
|
|
exit 33
|
|
fi
|
|
cat /sys/class/power_supply/BAT${BAT}/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%\n", status, charge)
|
|
printf("%s%d\n", status, charge)
|
|
if (charge > 25) {
|
|
print("#04B431\n")
|
|
} else if (charge > 20) {
|
|
print("#A8FF00\n")
|
|
} else if (charge > 15) {
|
|
print("#FFF600\n")
|
|
} else if (charge > 10) {
|
|
print("#FFAE00\n")
|
|
} else if (charge > 5) {
|
|
print("#FF0000\n")
|
|
} else {
|
|
exit 33
|
|
}
|
|
}
|
|
'
|