Skip to content

Instantly share code, notes, and snippets.

@cmj
Created March 8, 2022 03:37
Show Gist options
  • Save cmj/89091faacec248b1e072fd5dad141663 to your computer and use it in GitHub Desktop.
Save cmj/89091faacec248b1e072fd5dad141663 to your computer and use it in GitHub Desktop.
nvidia brightness control
#!/bin/bash
# nvidia brightness control
nvrc=~/.nvidia-settings-rc
# increments
brightness=.075
contrast=.05
gamma=.04
###
b=$(sed -n 's/.*RedBrightness=\(.*\)/\1/p' ${nvrc})
c=$(sed -n 's/.*RedContrast=\(.*\)/\1/p' ${nvrc})
g=$(sed -n 's/.*RedGamma=\(.*\)/\1/p' ${nvrc})
up() {
b1=$(bc <<< "${b}+${brightness}")
c1=$(bc <<< "${c}+${contrast}")
g1=$(bc <<< "${g}+${gamma}")
}
down() {
b1=$(bc <<< "${b}-${brightness}")
c1=$(bc <<< "${c}-${contrast}")
g1=$(bc <<< "${g}-${gamma}")
}
restore() {
b1=0.000000
c1=0.000000
g1=1.00000
}
die() {
[[ $* ]] && echo "$*"
exit 1
}
if [ -z "$1" ]; then
cat << eof
usage: ${0##*/} [OPTION]
-u adjust up
-d adjust down
-r reset
eof
exit 1
fi
case $1 in
-u)
up
shift;;
-d)
down
shift;;
-r)
restore
shift;;
*)
die "Unknown option '$1'";;
esac
sed -i 's/Brightness.*/Brightness='${b1}'/;s/Contrast.*/Contrast='${c1}'/;s/Gamma.*/Gamma='${g1}'/' ${nvrc}
nvidia-settings --load-config-only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment