I have a script that changes the display brightness using xrandr. It is my first bash script. I mainly had a lot of trouble with dealing with the floating point values. I think that is one of the main reasons the performance is bad.
1 #!/bin/bash
2 # increase/decrease display brightness of xrandr of both displays
3 # use:
4 # $ ./change_brightness [up/down (0/1)]
5
6 export current_brightness=$(xrandr --verbose | awk '/Brightness/ { print $2; exit }')
7
8 export increase=$1
9 export new_brightness=$current_brightness
10
11 if [ "$increase" = "1" ]; then
12 if [ $current_brightness != "1.0" ]; then
13 new_brightness="$current_brightness + 0.2"
14 fi
15 elif [ "$increase" = "0" ]; then
16 if [ $current_brightness != "0.20" ]; then
17 new_brightness="$current_brightness - 0.2"
18 fi
19 fi
20
21 new_brightness=$(bc <<< "$new_brightness")
22
23 xrandr --output eDP-1-1 --brightness $new_brightness
24 xrandr --output DP-0 --brightness $new_brightness
The performance isn't terrible, but any improvements would be highly appreciated. Also the improvements that have nothing to do with performance.