Last active
July 21, 2023 09:12
-
-
Save epanji/bc6f7bd601e6e342736089277d69a80b to your computer and use it in GitHub Desktop.
Intel Backlight CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Author: Panji Kusuma <epanji at gmail dot com> | |
# | |
# Assume user already in video group | |
# Place these 3 lines in /etc/rc.d/rc.local and uncomment the lines | |
# | |
# echo 100 > /sys/class/backlight/intel_backlight/brightness | |
# chmod 664 /sys/class/backlight/intel_backlight/brightness | |
# chown root:video /sys/class/backlight/intel_backlight/brightness | |
DEBUG=${DEBUG:-0} | |
RESULT=${RESULT:-100} | |
if [[ $1 =~ ^[0-9+-]+$ ]]; then | |
cd /sys/class/backlight/intel_backlight | |
read MAX < max_brightness | |
read CUR < brightness | |
MIN=$(($MAX / 20)) | |
if [[ $1 =~ ^[+-]$ ]]; then | |
RESULT=$(($CUR $1 $MIN)) | |
else | |
RESULT=$1 | |
fi | |
else | |
echo "Usage:" | |
echo " $0 <arg>" | |
echo "" | |
echo "The <arg> could be +, - or any integer." | |
echo "" | |
exit 1 | |
fi | |
# RESULT should be within MIN and MAX | |
if [[ $RESULT -gt $MAX ]]; then | |
RESULT=$MAX | |
elif [[ $RESULT -le 0 ]]; then | |
RESULT=$MIN | |
else | |
RESULT=${RESULT#-} | |
fi | |
# Main | |
if [[ $DEBUG -eq 0 ]]; then | |
echo $RESULT >> brightness 2> /dev/null | |
else | |
echo $RESULT | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment