Skip to content

Instantly share code, notes, and snippets.

@slava-sh
Created June 7, 2014 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slava-sh/98b3c0bc865484195b3e to your computer and use it in GitHub Desktop.
Save slava-sh/98b3c0bc865484195b3e to your computer and use it in GitHub Desktop.
#!/bin/bash
FILE='/sys/class/backlight/intel_backlight/brightness'
VALUES=(500 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000 12000 12421)
DEFAULT=9
current=$(cat $FILE)
current=${current,,}
case "$1" in
set|reset)
if [ -n "$2" ]; then
new=${2,,}
else
new=${VALUES[DEFAULT]}
fi
if [ $new -ge ${VALUES[0]} ] && [ $new -le ${VALUES[${#VALUES[@]} - 1]} ]; then
if echo $new >$FILE; then
echo "Brightness set from $current to $new"
else
exit 2
fi
else
echo "Incorrect brightness value: $new" >&2
exit 1
fi
;;
up|down)
for i in $(seq 0 $((${#VALUES[*]}-1))); do
if [ "${VALUES[$i]}" == "$current" ]; then
break
fi
done
if [ "${VALUES[$i]}" != "$current" ]; then
i=$DEFAULT
fi
case "$1" in
up)
i=$((i+1))
if [ "$i" -eq "${#VALUES[*]}" ]; then
echo "Brightness is already maximal"
else
new=${VALUES[$i]}
$0 set $new >/dev/null 2>&1 && echo "Brightness increased from $current to $new"
fi
;;
down)
i=$((i-1))
if [ "$i" -eq "-1" ]; then
echo "Brightness is already minimal"
else
new=${VALUES[$i]}
$0 set $new >/dev/null 2>&1 && echo "Brightness decreased from $current to $new"
fi
;;
esac
;;
*)
echo "Current brightness is $current"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment