dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

xrandr-brightness (1647B)


      1 #!/usr/bin/env bash
      2 if [ "$1" = "up" ]; then
      3   brightness="$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
      4   gamma="$(xrandr --verbose | grep Gamma | tr -d ' \t\n' |  awk -F: '{ printf "%f:%f:%f", 1/$2, 1/$3, 1/$4 }')"
      5   if  ! [ "$brightness" = "1.0" ]; then
      6     step=${2:-"0.05"}
      7     result=$(echo "$brightness $step" | awk '{ if ($1+$2 > 1) printf "1.0"; else printf "%f", $1+$2 }')
      8     xrandr --output LVDS-0 --gamma "$gamma" --brightness "$result"
      9   fi
     10 elif [ "$1" = "down" ]; then
     11   brightness="$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
     12   gamma="$(xrandr --verbose | grep Gamma | tr -d ' \t\n' |  awk -F: '{ printf "%f:%f:%f", 1/$2, 1/$3, 1/$4 }')"
     13   if  ! [ "$brightness" = "0.0" ]; then
     14     step=${2:-0.05}
     15     result=$(echo "$brightness $step" | awk '{ if ($1-$2 < 0) printf "0.0"; else printf "%f", $1-$2 }')
     16     xrandr --output LVDS-0 --gamma "$gamma" --brightness "$result"
     17   fi
     18 elif [ "$1" = "gamma" ]; then
     19   brightness="$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
     20   if [ "$2" = "night" ]; then
     21     xrandr --output LVDS-0 --gamma "1.1:0.7:0.6" --brightness "$brightness"
     22   else
     23     xrandr --output LVDS-0 --gamma "$2" --brightness "$brightness"
     24   fi
     25 elif [ "$1" = "get" ]; then
     26   if [ "$2" = "brightness" ]; then
     27      result=$(xrandr --verbose |grep Brightness | grep -o '[0-9\.]*')
     28      echo "$result" | awk '{ printf "%d%%", $1*100 }'
     29   else
     30     echo "Brightness: $(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
     31     echo "Gamma: $(xrandr --verbose | grep Gamma | tr -d ' \t\n' |  awk -F: '{ printf "%f:%f:%f", 1/$2, 1/$3, 1/$4 }')"
     32   fi
     33 else
     34   echo "up, down, gamma (r:g:b | night)"
     35 fi