Skip to content

Instantly share code, notes, and snippets.

@ottosch
Created January 9, 2025 13:52
Show Gist options
  • Save ottosch/ba101b32814c89eebc2626ac3fe00fd6 to your computer and use it in GitHub Desktop.
Save ottosch/ba101b32814c89eebc2626ac3fe00fd6 to your computer and use it in GitHub Desktop.
Change screen brightness for the terminal
#! /usr/bin/env bash
# Sets brightness to parameter level [0, max_brightness]
# Default: 10_000
default=10000
brightness=${1:-$default}
max="$(cat /sys/class/backlight/*/max_brightness)"
if test "$brightness" -eq "$brightness" 2>/dev/null; then # numeric value
if [ "$brightness" -gt "$max" ]; then
brightness="$max"
elif [ "$brightness" -lt 0 ]; then
brightness=0
fi
else
brightness="$default"
fi
echo "Setting brightness to $brightness"
echo "$brightness" | sudo tee /sys/class/backlight/*/brightness >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment