refractor: move code to abstract.sh enable unique and central color palette and progress bar
This commit is contained in:
65
modules/battery.sh
Executable file
65
modules/battery.sh
Executable file
@ -0,0 +1,65 @@
|
||||
DIR="/sys/class/power_supply"
|
||||
|
||||
if [[ "$BLOCK_INSTANCE" == "" ]]; then
|
||||
for BAT in $DIR/BAT*/; do
|
||||
[[ -f "${BAT}uevent" ]] && BATS+="$BAT/uevent "
|
||||
done
|
||||
else
|
||||
[[ -f "$DIR/BAT$BLOCK_INSTANCE/uevent" ]] && BATS="$DIR/BAT$BLOCK_INSTANCE/uevent"
|
||||
fi
|
||||
|
||||
if [[ "$BATS" == "" ]]; then
|
||||
echo " no battery "
|
||||
echo "n/a"
|
||||
exit 33
|
||||
fi
|
||||
|
||||
cat $BATS | gawk -v LONG="$LONG" -v COLORS="$COLORS" -v BAR="${BAR[*]}" -v COLOR="${COLOR[*]}" -v BW="${BW[*]}" -F "=" '
|
||||
|
||||
BEGIN {
|
||||
split(BAR, bar, / /)
|
||||
split(COLOR, color, / /)
|
||||
split(BW, bw, / /)
|
||||
interval = 100 / length(bar)
|
||||
efull = 0
|
||||
enow = 0
|
||||
status = ""
|
||||
}
|
||||
|
||||
/POWER_SUPPLY_STATUS=/ {
|
||||
if (status == "") {
|
||||
if ($2 == "Discharging") {
|
||||
status = ""
|
||||
} else if ($2 == "Charging") {
|
||||
status = "⚡"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/POWER_SUPPLY_ENERGY_FULL=/ { efull += $2 }
|
||||
/POWER_SUPPLY_ENERGY_NOW=/ { enow += $2 }
|
||||
|
||||
END {
|
||||
load = enow / efull * 100
|
||||
if (LONG) {
|
||||
printf("%d%\n%d\n", load, load)
|
||||
} else {
|
||||
for (i in bar) {
|
||||
if (load <= i * interval) {
|
||||
printf("%s\n%s\n", bar[i], bar[i])
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i in bw) {
|
||||
if (load <= i * interval) {
|
||||
if (COLORS) {
|
||||
printf("%s\n", color[i])
|
||||
} else {
|
||||
printf("%s\n", bw[i])
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
Reference in New Issue
Block a user