2023-05-21 14:24:34 +02:00

29 lines
687 B
Bash
Executable File

#!/usr/bin/env bash
function get_time_ms {
date -u +%s%3N
}
icons=("󰛩" "󱩒" "󰛨")
gen_output() {
icon="${icons[$(awk -v n="$(light)" 'BEGIN{print int(n/34)}')]}"
echo '{"percent": "'$(light)'", "icon": "'$icon'"}'
}
if [[ $(light 2>/dev/stdout 1>/dev/null | head -n1 | awk '{print $1}') == "No" ]]; then
echo '{"percent": 100.0, "icon": "󰛨"}'
elif [ "$1" = "" ]; then
# initial
last_time=$(get_time_ms)
gen_output
udevadm monitor | rg --line-buffered "backlight" | while read -r _; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
if [[ $delta -gt 50 ]]; then
gen_output
last_time=$(get_time_ms)
fi
done
fi