#!/bin/sh set -eu STEPS=16 MIN=2 max= get_b() { local b= b=$(brightnessctl --class=backlight get) || return 1 printf '%.0f\n' $(printf \ 'scale = 20;'$(: \ )'((%d - 1) * sqrt((%d - %d) * (%d - (2 * %d - %d)))) / '$(: \ )'(%d - %d)\n' \ ${STEPS} ${MIN} ${b} ${b} ${max} ${MIN} ${max} ${MIN} | bc) return 0 } set_b() { local b="${1}" shift 1 brightnessctl --class=backlight set $(printf '%.0f\n' $(printf \ 'scale = 20;'$(: \ )'%d + (1 - sqrt(1 - (%d / (%d - 1))^2)) * (%d - %d)\n' \ ${MIN} ${b} ${STEPS} ${max} ${MIN} | 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 max=$(brightnessctl --class=backlight max) b=$(get_b) || return 1 : $((b += 1)) : $((b ${dir}= 1)) [ ${b} -gt ${STEPS} ] && b=${STEPS} [ ${b} -lt 1 ] && b=1 : $((b -= 1)) set_b ${b} || return 1 return 0 } main "${@}"