From: Siraaj Khandkar Date: Wed, 19 Jan 2022 15:25:55 +0000 (-0500) Subject: Simplify monitor-brightness script X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=880ba5be4bae1dcd5cedaece7843d7e7fc194d54;p=khome.git Simplify monitor-brightness script --- diff --git a/home/bin/monitor-brightness b/home/bin/monitor-brightness index 70b795d..9688ebe 100755 --- a/home/bin/monitor-brightness +++ b/home/bin/monitor-brightness @@ -1,10 +1,5 @@ #! /bin/bash -error() { - printf 'Error: %s\n' "$1" >&2 - exit 1 -} - _get() { sudo ddcutil getvcp 10 | grep -o ' current value = \+[0-9]\+' | awk '{print $4}' } @@ -13,21 +8,15 @@ _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." + *) + 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