X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=home%2Fbin%2Fmonitor-brightness;h=07b7c4933b0000848a09f0872a94886541ca4e06;hb=HEAD;hp=70b795d3093a21bd4d43d68ba95133becf46b0cf;hpb=ba9438915745ea13cdd8007b1ee241d5c4d1ec11;p=khome.git diff --git a/home/bin/monitor-brightness b/home/bin/monitor-brightness index 70b795d..07b7c49 100755 --- a/home/bin/monitor-brightness +++ b/home/bin/monitor-brightness @@ -1,8 +1,11 @@ #! /bin/bash -error() { - printf 'Error: %s\n' "$1" >&2 - exit 1 +max() { + if [[ "$1" -gt "$2" ]]; then echo "$1"; else echo "$2"; fi +} + +min() { + if [[ "$1" -lt "$2" ]]; then echo "$1"; else echo "$2"; fi } _get() { @@ -13,21 +16,17 @@ _set() { sudo ddcutil setvcp 10 "$1" } -cmd="$1" -arg="$2" +args="$*" -case "$cmd" in +case "$args" in '') _get;; - get) _get;; - set) - case "$arg" in - '') error 'expected a numeric argument between 0 and 100, given nothing!';; - *) - if [[ "$arg" =~ ^[0-9]+$ && "$arg" -gt -1 && "$arg" -lt 101 ]]; then - _set "$arg" - else - error "expected a numeric argument between 0 and 100, but given '$arg'" - fi - esac;; - *) error "unrecognized command: $cmd. Expect either get or set." + i | inc | increase) _set "$(min $(( $(_get) + 5)) 100)";; + d | dec | decrease) _set "$(max $(( $(_get) - 5)) 0)";; + *) + if [[ "$args" =~ ^[0-9]+$ && "$args" -gt -1 && "$args" -lt 101 ]]; then + _set "$args" + else + printf 'Error: expected a numeric argument between 0 and 100, but given "%s"\n' "$args" >&2 + exit 1 + fi esac