diff options
Diffstat (limited to 'pkgs')
-rwxr-xr-x | pkgs/by-name/br/brightness/brightness.sh | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/pkgs/by-name/br/brightness/brightness.sh b/pkgs/by-name/br/brightness/brightness.sh index d0cccfee..5ad4eade 100755 --- a/pkgs/by-name/br/brightness/brightness.sh +++ b/pkgs/by-name/br/brightness/brightness.sh @@ -18,11 +18,8 @@ OPTIONS: Output the version and exit. COMMANDS: - up [VALUE] - Increase the brightness by VALUE or 5%. - - down [VALUE] - Decrease the brightness by VALUE or 5%. + set [VALUE] + Set the brightness to the specified percentage. ARGUMENTS: VALUE := [[seq 0 100]] @@ -33,17 +30,15 @@ EOF BACKLIGHT="/sys/class/backlight/%BACKLIGHT_NAME" brightness() { - offset="$1" + perc="$1" max="$(cat $BACKLIGHT/max_brightness)" - cur="$(cat $BACKLIGHT/brightness)" - percentage="$(echo | awk --assign=cur="$cur" --assign=max="$max" '{printf cur / max}')" - new="$(echo | awk --assign=per="$percentage" --assign=offset="$offset" '{printf per + (offset / 10)}')" + new="$(echo | awk --assign=per="$cur_perc" --assign=perc="$perc" '{printf (perc / 100)}')" output="$(echo | awk --assign=new="$new" --assign=max="$max" '{printf max * new}')" - echo "$output" | sudo tee "$BACKLIGHT/brightness" >/dev/null + echo "$output" > "$BACKLIGHT/brightness" } for arg in "$@"; do @@ -59,18 +54,19 @@ for arg in "$@"; do esac done +[ "$(id --user)" != 0 ] && die "This script requires root (as it needs to write into '$BACKLIGHT/brightness')" + case "$1" in -"up") - shift 1 - value="5" - [ -n "$1" ] && value="$1" - brightness "+$value" - ;; -"down") +"set") shift 1 - value="-5" - [ -n "$1" ] && value="$1" - brightness "-$value" + + if [ -n "$1" ]; then + value="$1" + else + die "No value specified"; + fi + + brightness "$value" ;; *) die "The command '$1' does not exist! See '--help' for a list" |