pyra-brightkey.sh 1.29 KB
Newer Older
1 2
#!/bin/sh

sebt3's avatar
sebt3 committed
3 4 5 6 7 8 9 10 11
help() {
	cat <<ENDHELP
$0 {screen|keyboard} {up|down|set|toggle} [value]
ENDHELP
}

case "$1" in
screen|[sS][Cc][rR]*)
	FTOG="/var/lib/pyra/screen-toggle-value"
sebt3's avatar
sebt3 committed
12
	FPAT="/sys/class/backlight/backlight"
sebt3's avatar
sebt3 committed
13 14 15
	minbright=1;;
keyboard|[kK][eE][yY]*)
	FTOG="/var/lib/pyra/keyboard-toggle-value"
sebt3's avatar
sebt3 committed
16
	FPAT="/sys/class/backlight/keyboard-backlight"
sebt3's avatar
sebt3 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
	minbright=0;;
*)	help "$0"
	exit 1;;
esac
FCUR="$FPAT/actual_brightness"
FMAX="$FPAT/max_brightness"
FSET="$FPAT/brightness"
curbright="$(cat "$FCUR")"
maxbright="$(cat "$FMAX")"
newbright=$curbright
case "$2" in
set|[sS][eE][tT])
	if [ ! $3 ]; then
		newbright=$(zenity --scale --text "pick a number" "--min-value=$minbright" "--max-value=$maxbright" "--value=$curbright" --step 1);
	else
		newbright=$3
33
	fi
sebt3's avatar
sebt3 committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	if [ ! $newbright ]; then
		exit 0
	fi;;
up|[uU][pP])
	if [ ! $3 ]; then
		newbright=$(($curbright+1))
	else
		newbright=$(($curbright+$3))
	fi;;
down|[dD][oO][wW][nN])
	if [ ! $3 ]; then
		newbright=$(($curbright-1))
	else
		newbright=$(($curbright-$3))
	fi;;
toggle|[tT][oO][gG]*)		
	if [ $curbright = 0 ]; then
		newbright="$( cat $FTOG)"
	else
		echo $curbright > $FTOG
54
		minbright=0
sebt3's avatar
sebt3 committed
55 56 57 58 59 60 61 62 63
		newbright=0	
	fi;;
*)
	help "$0"
	exit 1;;
esac
[ $newbright -le $minbright ] && newbright=$minbright
[ $newbright -ge $maxbright ] && newbright=$maxbright
echo $newbright > $FSET