diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/bright | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/bright b/bin/bright new file mode 100755 index 0000000..7aa0801 --- /dev/null +++ b/bin/bright @@ -0,0 +1,62 @@ +#!/bin/sh + +set -eu + +get_b() +{ + local b= + + b=$(brightnessctl --class=backlight get) || return 1 + printf '%.0f\n' $(printf \ + 'scale = 4; (7 * sqrt((2 - %d) * (%d - 3102))) / 1550\n' \ + ${b} ${b} | bc) + + return 0 +} + +set_b() +{ + local b="${1}" + shift 1 + + brightnessctl --class=backlight set $(printf '%.0f\n' \ + $(printf 'scale = 4; 2 + (1 - sqrt(1 - (%d / 7)^2)) * 1550\n' \ + ${b} | bc)) || return 1 + + return 0 +} + +usage() +{ + printf 'Usage: %s {-|+}\n' "${0}" + + return 0 +} + +main() +{ + local dir= + local b= + + if [ ${#} -ne 1 ]; then + usage 1>&2 + return 1 + fi + dir="${1}" + shift 1 + + case "${dir}" in + -|+);; + *) + usage 1>&2 + return 1 + ;; + esac + + b=$(get_b) || return 1 + set_b $((${b} ${dir} 1)) || return 1 + + return 0 +} + +main "${@}" |