#!/usr/bin/env clopper-ob-bash ## # Change brightness and show a notification multiply-by-10-and-strip-decimals() { declare number="$1" bc <<<"10 * $number" | sed 's/\..*$//g' } current-brightness() { xrandr --current --verbose | grep -Pom 1 '(?<=Brightness: ).*' } current-output() { xrandr --query | grep -Po '^.*(?= connected)' } set-brightness() { declare output="$1" brightness="$2" xrandr --output "$output" --brightness "$brightness" } notify-brightness() { notify-send.sh -i "$(icon brightness)" \ --replace-file=$HOME/.cache/clopper-ob/brightness.id \ " $(bar $((2 * $(multiply-by-10-and-strip-decimals $(current-brightness)))))" } increase-brightness() { if [[ $(multiply-by-10-and-strip-decimals $(current-brightness)) -ge 12 ]]; then return 0 fi set-brightness "$(current-output)" "$(bc <<<"$(current-brightness) + 0.1")" } decrease-brightness() { set-brightness "$(current-output)" "$(bc <<<"$(current-brightness) - 0.1")" } if [[ $1 == '+' ]]; then increase-brightness elif [[ $1 == '-' ]]; then decrease-brightness fi notify-brightness