Created
November 28, 2025 22:59
-
-
Save unreturned/3bb889fe62ad7f7a068fb0135d660b57 to your computer and use it in GitHub Desktop.
bright function for my lenovo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bright() { | |
| if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
| echo "Usage: $FUNCNAME [-s|-m|-v VALUE|-p PERCENT]" | |
| echo " -s show current brightness" | |
| echo " -m set max brightness" | |
| echo " -v set specific value" | |
| echo " -p set percent (0-100)" | |
| echo " no args: show and set max if needed" | |
| return 0 | |
| fi | |
| local path="/sys/class/backlight/intel_backlight" | |
| local max=$(cat "$path/max_brightness") | |
| local cur=$(cat "$path/brightness") | |
| local pct=$((cur * 100 / max)) | |
| case "${1:-}" in | |
| -s) echo "Brightness: $cur/$max ($pct%)";; | |
| -m) echo "$max" | sudo tee "$path/brightness" > /dev/null && echo "Set to max: $max";; | |
| -v) [ -z "$2" ] && echo "Error: -v needs VALUE" && return 1 | |
| echo "$2" | sudo tee "$path/brightness" > /dev/null && echo "Set to: $2";; | |
| -p) [ -z "$2" ] && echo "Error: -p needs PERCENT" && return 1 | |
| local val=$((max * $2 / 100)) | |
| echo "$val" | sudo tee "$path/brightness" > /dev/null && echo "Set to: $val ($2%)";; | |
| "") echo "Current: $cur/$max ($pct%)" | |
| [ "$cur" -lt "$max" ] && echo "$max" | sudo tee "$path/brightness" > /dev/null && echo "Set to max: $max" || echo "Already at max";; | |
| *) echo "Error: Unknown option. Use: $FUNCNAME -h"; return 1;; | |
| esac | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment