Skip to content

Instantly share code, notes, and snippets.

@1player
Created January 24, 2023 12:44
Show Gist options
  • Save 1player/b58e87580c78b8a134d8b77785b61f3e to your computer and use it in GitHub Desktop.
Save 1player/b58e87580c78b8a134d8b77785b61f3e to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
i2c_from_output() {
dir=$(ls -d /sys/bus/pci/devices/0000:03:00.0/drm/card*/card*-"$1"/i2c*)
dev=$(basename "$dir")
echo "/dev/$dev"
}
change_brightness() {
brightness=$(ddccontrol -r 0x10 -W "$1" "dev:$(i2c_from_output DP-1)" | tail -n 1 | cut -d '/' -f 2)
if grep -q enabled /sys/bus/pci/devices/0000:03:00.0/drm/card*/card*-DP-2/enabled; then
ddccontrol -r 0x10 -w "$brightness" "dev:$(i2c_from_output DP-2)"
fi
}
case $1 in
up)
change_brightness +10
;;
down)
change_brightness -10
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment