Skip to content

Instantly share code, notes, and snippets.

@Einenlum
Created January 19, 2022 00:26
Show Gist options
  • Save Einenlum/3e6c574098f73639634660be9cede39b to your computer and use it in GitHub Desktop.
Save Einenlum/3e6c574098f73639634660be9cede39b to your computer and use it in GitHub Desktop.
Script to use xbacklight and prevent full black screen
#!/bin/sh
val=$(xbacklight -get)
increase_light() {
# Try to be a bit progressive when in low brightness
if [ $val -le 20 ] ; then
percent=2
else
percent=5
fi
new_value=$(($val + $percent))
if [ $new_value -ge 100 ] ; then
exit 0
fi
xbacklight -inc $percent
}
decrease_light() {
if [ $val -ge 50 ] ; then
percent=10
elif [ $val -ge 30 ] ; then
percent=5
else
percent=2
fi
new_value=$(($val - $percent))
if [ $new_value -le 1 ] ; then
exit 0
fi
xbacklight -dec $percent
}
if [ "$1" = "inc" ] ; then
increase_light
else
decrease_light
fi
# Use:
# `light.sh inc` or `light.sh dec`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment