25 lines
750 B
Bash
Executable file
25 lines
750 B
Bash
Executable file
#!/usr/bin/env bash
|
|
# docstring=simplifies the brightnessctl command
|
|
set -E -o pipefail
|
|
shopt -s failglob
|
|
export LC_ALL=C.UTF8
|
|
|
|
# when invoked without parameter will print current brightness in percent
|
|
# it accepts a parameter from 0 to 100 for brightness. Please ommit the % symbol.
|
|
|
|
if [[ "$1" == "--toggle" ]]; then
|
|
if [[ "$(brightnessctl get)" == "0" ]]; then
|
|
brightnessctl --restore || brightnessctl set '50%' # just in case --restore fails
|
|
else
|
|
brightnessctl --save && brightnessctl set 0
|
|
fi
|
|
exit 0 # if toggle is used don't continue
|
|
fi
|
|
|
|
# default path
|
|
percentage(){ brightnessctl -m | cut -d',' -f4; }
|
|
printf "current: "; percentage
|
|
if [[ -n "$1" ]]; then
|
|
brightnessctl set "$1\%" > /dev/null
|
|
printf "now: "; percentage
|
|
fi
|