#!/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 "${@}"