aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-06-01 17:18:09 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-06-01 17:18:09 +0200
commit2d76e48b426cfc7444e398e3fbff0290ee98b387 (patch)
tree0804252bf816e77175646ed8e35b8a74a59827f7 /pkgs
parentfix(pkgs/brightness): Actually change something (diff)
downloadnixos-config-2d76e48b426cfc7444e398e3fbff0290ee98b387.zip
fix(pkgs/brightness): Greatly improve the UX
Diffstat (limited to 'pkgs')
-rwxr-xr-xpkgs/by-name/br/brightness/brightness.sh36
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"