-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.sh
executable file
·57 lines (45 loc) · 1.92 KB
/
a.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# # control brightness
# # example ./a.sh -10
# # example ./a.sh +10
# backlight=/sys/class/backlight/amdgpu_bl1/brightness
# currentbrightness=(`cat $backlight`)
# value=`expr $currentbrightness + $1`
# echo $value%
# brightnessctl set $value
# old one not working !
MON="eDP" # Discover monitor name with: xrandr | grep " connected"
MON1="HDMI-1" # Discover monitor name with: xrandr | grep " connected"
STEP=5 # Step Up/Down brightnes by: 5 = ".05", 10 = ".10", etc.
CurrBright=$( xrandr --verbose --current | grep ^"$MON" -A5 | tail -n1 )
CurrBright="${CurrBright##* }" # Get brightness level with decimal place
Left=${CurrBright%%"."*} # Extract left of decimal point
Right=${CurrBright#*"."} # Extract right of decimal point
MathBright="0"
[[ "$Left" != 0 && "$STEP" -lt 10 ]] && STEP=10 # > 1.0, only .1 works
[[ "$Left" != 0 ]] && MathBright="$Left"00 # 1.0 becomes "100"
[[ "${#Right}" -eq 1 ]] && Right="$Right"0 # 0.5 becomes "50"
MathBright=$(( MathBright + Right ))
[[ "$1" == "Up" || "$1" == "+" ]] && MathBright=$(( MathBright + STEP ))
[[ "$1" == "Down" || "$1" == "-" ]] && MathBright=$(( MathBright - STEP ))
[[ "${MathBright:0:1}" == "-" ]] && MathBright=0 # Negative not allowed
[[ "$MathBright" -gt 999 ]] && MathBright=999 # Can't go over 9.99
if [[ "${#MathBright}" -eq 3 ]] ; then
MathBright="$MathBright"000 # Pad with lots of zeros
CurrBright="${MathBright:0:1}.${MathBright:1:2}"
else
MathBright="$MathBright"000 # Pad with lots of zeros
CurrBright=".${MathBright:0:2}"
fi
if [[ $MathBright -lt 10000 ]]
then
exit 0
elif [[ $MathBright -gt 100000 ]]
then
exit 0
fi
xrandr --output "$MON" --brightness "$CurrBright" # Set new brightness
xrandr --output "$MON1" --brightness "$CurrBright"
# Display current brightness
printf "Monitor $MON "
echo $( xrandr --verbose --current | grep ^"$MON" -A5 | tail -n1 )