-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished project, everything working as expected
- Loading branch information
Showing
1 changed file
with
91 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,108 @@ | ||
#! /bin/bash | ||
|
||
echo "llight 1.0 2020" | ||
# main.sh | ||
# Josue Teodoro Moreira <jteodomo@gmail.com> <josue.moreira2@etec.sp.gov.br> | ||
# December 13, 2020 | ||
|
||
target_folder=/sys/class/backlight/intel_backlight/ | ||
target_folder=/sys/class/backlight/intel_backlight | ||
current_brightness=$(cat ${target_folder}/brightness) | ||
max_brightness=$(cat ${target_folder}/max_brightness) | ||
|
||
# functions | ||
# print usage / help | ||
usage() | ||
{ | ||
echo "$(basename $0) -[h | v | g | s | i | d]" | ||
echo " -h shows this help and exit" | ||
echo " -v shows version and exit" | ||
echo " -g shows current brightness and exit" | ||
echo " -s changes brightness by given value. Must be between 1 and ${max_brightness}" | ||
echo " -i increases brightness by given value" | ||
echo " -d decreases brightness by given value" | ||
echo "$(basename $0) -[h | v | g | s | i | d]." | ||
echo | ||
echo "Make sure to run llight with administrator rights. e. g. 'sudo llight -h'." | ||
echo | ||
echo " -h shows this help and exit." | ||
echo " -v shows version and exit." | ||
echo " -g shows current brightness and exit." | ||
echo " -s changes brightness by given value. Must be between 1 and 100." | ||
echo " -i increases brightness by given value." | ||
echo " -d decreases brightness by given value." | ||
|
||
exit 1 | ||
} | ||
|
||
if [ $# -eq 0 ]; then | ||
set_by_value() | ||
{ | ||
if [ ${1} -lt 1 ] || [ ${1} -gt 100 ]; then | ||
echo "Value must be between 1 and 100." | ||
|
||
usage | ||
fi | ||
|
||
let new_brightness=$((${max_brightness} / 100 * ${1})) | ||
echo "${new_brightness}" | sudo tee ${target_folder}/brightness > /dev/null | ||
} | ||
|
||
increase_by_value() | ||
{ | ||
if [ $((${current_brightness} + ${1})) -gt ${max_brightness} ]; then | ||
echo "Already on maximum brightness. Try a smaller number or -s instead." | ||
|
||
usage | ||
fi | ||
|
||
let new_brightness=$((${current_brightness} + ${1})) | ||
echo "${new_brightness}" | sudo tee ${target_folder}/brightness > /dev/null | ||
} | ||
|
||
decrease_by_value() | ||
{ | ||
if [ $((${current_brightness} - ${1})) -lt 1 ]; then | ||
echo "Already on minimum brightness. Try a smaller number or -s instead." | ||
|
||
usage | ||
fi | ||
|
||
let new_brightness=$((${current_brightness} - ${1})) | ||
echo "${new_brightness}" | sudo tee ${target_folder}/brightness > /dev/null | ||
} | ||
|
||
if [ $# -gt 2 ] || [ $# -eq 0 ] | ||
then | ||
usage | ||
fi | ||
|
||
# truncate -s 0 ${target_folder}/brightness | ||
# echo ${current_brightness} > ${target_folder}/brightness | ||
# get options | ||
options=":hvgsid" | ||
getopts ${options} args | ||
|
||
case ${args} in | ||
h) | ||
usage | ||
|
||
;; | ||
v) | ||
echo "llight 1.0" | ||
echo "Developed by Josue Teodoro Moreira" | ||
|
||
;; | ||
g) | ||
echo ${current_brightness} | ||
|
||
;; | ||
s) | ||
set_by_value ${2} | ||
|
||
;; | ||
i) | ||
increase_by_value ${2} | ||
|
||
;; | ||
d) | ||
decrease_by_value ${2} | ||
|
||
;; | ||
*) | ||
echo "Invalid argument -${OPTARG}" | ||
echo | ||
usage | ||
|
||
;; | ||
esac | ||
|
||
|
||
exit 0 |