diff options
Diffstat (limited to 'bin/backlight')
-rwxr-xr-x | bin/backlight | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/bin/backlight b/bin/backlight deleted file mode 100755 index be0dadf..0000000 --- a/bin/backlight +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env bash -# -# Sets backlight through /sys/class/backlight/intel_backlight/brightness -# Note: This requires the file to be user-writable! -# Changes can be applied either by (positive or negative) relative increment -# [-i] or as an absolute value [-s] (in percentage). - -set -euo pipefail - -# brightness steps in percentage -brightness_step_size=5 -brightness_device=/sys/class/backlight/intel_backlight/brightness -brightness_max_device=/sys/class/backlight/intel_backlight/max_brightness -calculated_brightness=0 -amount=0 - -brightness_steps=$(echo "100/${brightness_step_size}" |bc -l) -maximum_brightness_raw=$(cat $brightness_max_device) -current_brightness_raw=$(cat $brightness_device) -brightness_one_percent_raw=$(echo "${maximum_brightness_raw}/100" |bc -l) -current_brightness_percentage=$(echo "${current_brightness_raw}/(${maximum_brightness_raw}/100)" |bc -l) -current_brightness_remainder=$(echo "${current_brightness_percentage}%${brightness_step_size}"|bc -l) -current_step=$(echo ${current_brightness_percentage}/${brightness_step_size}|bc -l) - -check_if_number() { - if [[ $1 =~ ^[!\-0-9]+$ ]]; then - echo "Not an Integer: $1" - exit 1 - fi -} - -calculate_increment() { - check_if_number $1 - if [ $1 -eq 0 ]; then - echo "There's nothing to do." - exit 1 - fi - if [ $1 -gt 0 ]; then - if [ $(printf '%.0f' $current_brightness_percentage) -eq 100 ]; then - echo "Already at 100%" - exit 0 - elif [ $(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) -gt 100 ]; then - calculated_brightness=100 - else - calculated_brightness=$(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) - fi - else - if [ $(printf '%.0f' $current_brightness_percentage) -eq 0 ]; then - echo "Already at 0%" - exit 0 - elif [ $(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) -lt 0 ]; then - calculated_brightness=0 - else - calculated_brightness=$(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) - fi - fi -} - -calculate_percentage() { - check_if_number $1 - if [ $1 -lt 0 ] || [ $1 -gt 100 ]; then - echo "Invalid range: $1" - exit 1 - fi - calculated_brightness=$1 -} - -percentage_to_raw() { - printf '%.0f' $(echo "$1*${brightness_one_percent_raw}"|bc -l) -} - -set_brightness() { - echo "$(percentage_to_raw $calculated_brightness)" > $brightness_device -} - -print_help() { - echo -e "Usage: $0 [-i <increment_in_percent>] [-s <brightness_in_percent>]" - exit 0 -} - -if [ ${#@} -gt 0 ]; then - while getopts 'hi:s:' flag; do - case "${flag}" in - h) - print_help - ;; - i) - calculate_increment $OPTARG - ;; - s) - calculate_percentage $OPTARG - ;; - *) - echo "Error! Try '${0} -h'." - exit 1 - ;; - esac - done -else - echo "$current_brightness_percentage" - exit 0 -fi - -set_brightness |