pub / dotfiles

Configuration of software on my computer
git clone https://src.jayvii.de/pub/dotfiles.git
Home | Log | Files | Exports | Refs | RSS

brightness.sh (793B)


      1 #!/usr/bin/env bash
      2 
      3 DEV="/sys/class/backlight/intel_backlight"
      4 MAX=$(cat "${DEV}/max_brightness")
      5 CUR=$(cat "${DEV}/brightness")
      6 PER=$((($CUR * 100) / $MAX))
      7 
      8 # If no argument is given, return current value
      9 if [[ -z $1 ]]; then
     10   echo "$PER"
     11   exit 0
     12 fi
     13 
     14 # increasing brightness
     15 if [[ "$1" == "inc" ]]; then
     16 
     17   # calculate new value in percent, cap at 100%
     18   PER_NEW=$((${PER} + ${2}))
     19   if [[ $PER_NEW -gt 100 ]]; then
     20     PER_NEW=100
     21   fi
     22 
     23 fi
     24 
     25 # decrease brightness
     26 if [[ "$1" == "dec" ]]; then
     27 
     28   # calculate new value in percent, capt at 5%
     29   PER_NEW=$((${PER} - ${2}))
     30   if [[ $PER_NEW -lt 5 ]]; then
     31     PER_NEW=5
     32   fi
     33 
     34 fi
     35 
     36 # calculate numerical value
     37 CUR_NEW=$(((${MAX} * ${PER_NEW}) / 100))
     38 
     39 # set new value
     40 echo "Setting brightness to $CUR_NEW"
     41 echo "$CUR_NEW" > "${DEV}/brightness"