diff options
author | David Runge <david.runge@native-instruments.de> | 2018-11-24 14:19:45 +0100 |
---|---|---|
committer | David Runge <david.runge@native-instruments.de> | 2018-11-24 14:19:45 +0100 |
commit | f4fec3ab8e56e82bf7904c3c19876e2f4e13667d (patch) | |
tree | 23a4dd266333fc6cfeb5ee05c6000ced30724098 /bin/backlight | |
parent | 31895b1b525ab673becdb10c7a421f71510f6354 (diff) | |
parent | de1f86528b58faa0844f24b9edb63e5837dd7444 (diff) | |
download | dotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.tar.gz dotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.tar.bz2 dotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.tar.xz dotfiles-f4fec3ab8e56e82bf7904c3c19876e2f4e13667d.zip |
Merge branch 'master' of git.sleepmap.de:config/dotfiles
* 'master' of git.sleepmap.de:config/dotfiles: (36 commits)
.config/packages-community.txt: Adding pd-lua.
.config/systemd/user/mpd@.service: Adding local override for mpd@ user service. Raising LimitRTPrio to 75, as some threads in mpd apparently require it.
.config/jack/*: Changing all configurations for jack@ user service (as its layout has changed).
.gitignore: Removing ignore of .config/systemd (time to add some local overrides).
.config/packages-aur.txt: Removing ssr (now in [community]).
.config/systemd/user/jack@.service: Adding a local jack@ user service, so no package is required.
.config/packages-community.txt: Adding dragonfly-reverb, libmusicxml, ssr and wolf-shaper.
.ncmpcpp/config: Switching to local visualizer fifo. Using visualizer_type ellipse.
.zsh.after/aliases.zsh: Removing useless pacsearch overloading.
bin/setup_screens: Fixing and simplifying various things with the help of shellcheck. Using a separate get_display function to retrieve DISPLAY.
bin/xorg_autolock: Properly quoting variables. Abstracting lock_cmd.
bin/xorg_lock: Properly quote variables. Rename variables for better readibility.
.xprofile: Repaired with the help of shellcheck.
.config/packages-community.txt: Adding marsyas.
.config/packages-aur.txt: Removing gmsynth.lv2 (now in community). Adding librenms and patroneo-git.
.config/packages-community.txt: Adding ams-lv2, beatslash-lv2, gmsynth.lv2, lib32-fluidsynth, lsp-plugins, lvtk, stk and removing ssmtp.
bin/cs: Fixing script according to shellcheck.
.config/packages-community.txt: Adding nextcloud-app-spreed.
.vim/addons-settings.vim: Adding supercollider settings for split in tmux.
.config/linuxsampler.org/Qsampler.conf: Remove, because it makes no sense in repo.
...
Diffstat (limited to 'bin/backlight')
-rwxr-xr-x | bin/backlight | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/backlight b/bin/backlight new file mode 100755 index 0000000..ac8a466 --- /dev/null +++ b/bin/backlight @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# set backlight through sysfs + +set -euo pipefail + +# brightness steps in percentage +brightness_step_size=5 +brightness_device=/sys/class/backlight/intel_backlight/brightness +brightness_max_device=/sys/class/backlight/intel_backlight/max_brightness +calculated_brightness=0 +amount=0 + +brightness_steps=$(echo "100/${brightness_step_size}" |bc -l) +maximum_brightness_raw=$(cat $brightness_max_device) +current_brightness_raw=$(cat $brightness_device) +brightness_one_percent_raw=$(echo "${maximum_brightness_raw}/100" |bc -l) +current_brightness_percentage=$(echo "${current_brightness_raw}/(${maximum_brightness_raw}/100)" |bc -l) +current_brightness_remainder=$(echo "${current_brightness_percentage}%${brightness_step_size}"|bc -l) +current_step=$(echo ${current_brightness_percentage}/${brightness_step_size}|bc -l) + +check_if_number() { + if [[ $1 =~ ^[!\-0-9]+$ ]]; then + echo "Not an Integer: $1" + exit 1 + fi +} + +calculate_increment() { + check_if_number $1 + if [ $1 -eq 0 ]; then + echo "There's nothing to do." + exit 1 + fi + if [ $1 -gt 0 ]; then + if [ $(printf '%.0f' $current_brightness_percentage) -eq 100 ]; then + echo "Already at 100%" + exit 0 + elif [ $(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) -gt 100 ]; then + calculated_brightness=100 + else + calculated_brightness=$(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) + fi + else + if [ $(printf '%.0f' $current_brightness_percentage) -eq 0 ]; then + echo "Already at 0%" + exit 0 + elif [ $(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) -lt 0 ]; then + calculated_brightness=0 + else + calculated_brightness=$(printf '%.0f' $(echo "${current_brightness_percentage}+$1"| bc)) + fi + fi +} + +calculate_percentage() { + check_if_number $1 + if [ $1 -lt 0 ] || [ $1 -gt 100 ]; then + echo "Invalid range: $1" + exit 1 + fi + calculated_brightness=$1 +} + +percentage_to_raw() { + printf '%.0f' $(echo "$1*${brightness_one_percent_raw}"|bc -l) +} + +set_brightness() { + echo "$(percentage_to_raw $calculated_brightness)" > $brightness_device +} + +print_help() { + echo -e "Usage:\n $0 -d <decrement_by_x_percent> \n or $0 -i <increment_by_x_percent>" + exit 1 +} + +if [ ${#@} -gt 0 ]; then + while getopts 'hi:s:' flag; do + case "${flag}" in + h) + print_help + ;; + i) + calculate_increment $OPTARG + ;; + s) + calculate_percentage $OPTARG + ;; + *) + echo "Error! Try '${0} -h'." + exit 1 + ;; + esac + done +else + print_help +fi + +set_brightness |