Last active
May 20, 2016 17:28
-
-
Save etcwilde/d6af7f4aed3536eba968d19d60b2379b to your computer and use it in GitHub Desktop.
Hacky hacks to make things work in Linux
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
# Evan Wilde <[email protected]> | |
# May 19 2016 | |
# /usr/lib/systemd/system/brightness.service | |
# Grants non-root permissions to the backlight file so that it can be set by a user process | |
# | |
[Unit] | |
Description=Grants non-root write access to the brightness file | |
[Service] | |
Type=oneshot | |
RemainAfterExit=yes | |
ExecStart=/bin/chmod 666 /sys/class/backlight/intel_backlight/brightness |
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 | |
# Evan Wilde <[email protected]> | |
# May 2016 | |
# Allows a user to make adjustments to the monitor brightness | |
brightness_directory="/sys/class/backlight/intel_backlight" | |
max_brightness=`cat $brightness_directory/max_brightness` | |
current_brightness=`cat $brightness_directory/brightness` | |
num_re='^[1-9][0-9]*$' | |
option="${1}" | |
case ${option} in | |
++) # Increase Backlight | |
number=${2-5} | |
if ! [[ $number =~ $num_re ]] ; then | |
number=5 | |
fi | |
if [[ $max_brightness -lt $((current_brightness + number)) ]] ; then | |
echo $max_brightness > $brightness_directory/brightness | |
else | |
echo $((current_brightness + number)) > $brightness_directory/brightness | |
fi | |
;; | |
--) # Decrease backlight | |
number=${2-5} | |
if ! [[ $number =~ $num_re ]] ; then | |
number=5 | |
fi | |
if [[ 0 -gt $((current_brightness - number)) ]] ; then | |
echo 0 >> $brightness_directory/brightness | |
else | |
echo $((current_brightness - number)) > $brightness_directory/brightness | |
fi | |
;; | |
+) echo $max_brightness > $brightness_directory/brightness ;; # Set to max | |
-) echo 0 > $brightness_directory/brightness ;; # Set to min | |
=) # Set brightness value | |
number=${2-5} | |
if ! [[ $number =~ $num_re ]] ; then | |
number=$max_brightness | |
fi | |
if [[ $number -le 0 ]] ; then | |
number=0 | |
elif [[ $number -ge $max_brightness ]] ; then | |
number=$max_brightness | |
fi | |
echo $number > $brightness_directory/brightness | |
;; | |
*) echo " `basename ${0}`: usage: [++ [LEVEL] | -- [LEVEL] | + | - | = [LEVEL]]" | |
exit 1 ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment