Implement monitor-brightness script
authorSiraaj Khandkar <siraaj@khandkar.net>
Tue, 18 Jan 2022 15:49:41 +0000 (10:49 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Tue, 18 Jan 2022 15:49:41 +0000 (10:49 -0500)
home/bin/monitor-brightness [new file with mode: 0755]

diff --git a/home/bin/monitor-brightness b/home/bin/monitor-brightness
new file mode 100755 (executable)
index 0000000..70b795d
--- /dev/null
@@ -0,0 +1,33 @@
+#! /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}'
+}
+
+_set() {
+    sudo ddcutil setvcp 10 "$1"
+}
+
+cmd="$1"
+arg="$2"
+
+case "$cmd" 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."
+esac
This page took 0.027352 seconds and 4 git commands to generate.