This repository has been archived on 2019-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
simple-i3blocks/modules/backlight.sh

47 lines
1.2 KiB
Bash

DIR="/sys/class/backlight"
if [[ -d "$DIR/acpi_video0" ]]; then
DIR="$DIR/acpi_video0"
elif [[ -d "$DIR/intel_backlight" ]]; then
DIR="$DIR/intel_backlight"
else
printf "no backlight\nn/a\n"
exit 33
fi
cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" '
BEGIN {
split(BAR, bar, / /)
split(COLOR, color, / /)
split(BW, bw, / /)
interval = 100 / length(bar)
}
NR == 1 { current_brightness = $1 }
NR == 2 { maximum_brightness = $1 }
END {
load = ( current_brightness / maximum_brightness ) * 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
}
}
}
'