Commit | Line | Data |
---|---|---|
ba943891 SK |
1 | #! /bin/bash |
2 | ||
3f43e4e0 SK |
3 | max() { |
4 | if [[ "$1" -gt "$2" ]]; then echo "$1"; else echo "$2"; fi | |
5 | } | |
6 | ||
7 | min() { | |
8 | if [[ "$1" -lt "$2" ]]; then echo "$1"; else echo "$2"; fi | |
9 | } | |
10 | ||
ba943891 SK |
11 | _get() { |
12 | sudo ddcutil getvcp 10 | grep -o ' current value = \+[0-9]\+' | awk '{print $4}' | |
13 | } | |
14 | ||
15 | _set() { | |
16 | sudo ddcutil setvcp 10 "$1" | |
17 | } | |
18 | ||
880ba5be | 19 | args="$*" |
ba943891 | 20 | |
880ba5be | 21 | case "$args" in |
ba943891 | 22 | '') _get;; |
3f43e4e0 SK |
23 | i | inc | increase) _set "$(min $(( $(_get) + 5)) 100)";; |
24 | d | dec | decrease) _set "$(max $(( $(_get) - 5)) 0)";; | |
880ba5be SK |
25 | *) |
26 | if [[ "$args" =~ ^[0-9]+$ && "$args" -gt -1 && "$args" -lt 101 ]]; then | |
27 | _set "$args" | |
28 | else | |
29 | printf 'Error: expected a numeric argument between 0 and 100, but given "%s"\n' "$args" >&2 | |
30 | exit 1 | |
31 | fi | |
ba943891 | 32 | esac |