diff options
Diffstat (limited to 'scripts/slight')
-rwxr-xr-x | scripts/slight | 54 |
1 files changed, 15 insertions, 39 deletions
diff --git a/scripts/slight b/scripts/slight index 7f1b03a..0f8cba0 100755 --- a/scripts/slight +++ b/scripts/slight @@ -1,5 +1,7 @@ #!/bin/sh +. slib + help() { cat << EOF ${0}: Wrapper script to change backlight @@ -13,61 +15,35 @@ options: NOTE: Script interprets values as percentages EOF -} -err() { - for line in "${@}"; do - echo "${line}" >&2 - done - exit 1 +exit 0 } -run() { - if ! ${1} > /dev/null 2>&1; then - err "${2}" - fi - - [ -n "${3}" ] && echo "${3}" +check_program "brightnessctl" - slreload || echo "Warning: Failed to reload slstatus" >&2 +[ ${#} != 1 ] && [ ${#} != 2 ] && invalid_use - exit 0 -} +while getopts "i:d:s:ph" option; do + case "${option}" in + i) run --reload-status "brightnessctl set +${OPTARG}%" ;; -if ! command -v brightnessctl > /dev/null 2>&1; then - err "${0}: brightnessctl must be installed" -fi + d) run --reload-status "brightnessctl set ${OPTARG}-%" ;; -if [ ${#} != 1 ] && [ ${#} != 2 ]; then - err "${0}: Invalid usage" "Try '${0} -h' for help." -fi + s) run --reload-status "brightnessctl set ${OPTARG}%" ;; -while getopts "i:d:s:ph" option; do - case "${option}" in - i) - run "brightnessctl set +${OPTARG}%" \ - "${0}: Failed to increase brightness" - ;; - d) - run "brightnessctl set ${OPTARG}-%" \ - "${0}: Failed to decrease brightness" - ;; - s) - run "brightnessctl set ${OPTARG}%" \ - "${0}: Failed to set brightness" - ;; p) - if ! echo $(( (`brightnessctl g` * 100) / `brightnessctl m` )); then + if ! echo $(( ($(brightnessctl g) * 100) / $(brightnessctl m) )); then err "Failed to get current brightness" else exit 0 fi ;; - h) help; exit 0 ;; + h) help ;; - *) err "Try '${0} -h' for help." ;; + *) invalid_use -h ;; esac done -err "${0}: Invalid usage" "Try '${0} -h' for help." +# Unreachable +invalid_use |