66 lines
1.5 KiB
Bash
66 lines
1.5 KiB
Bash
|
#!/usr/bin/bash
|
||
|
|
||
|
SAVE_FILE="${HOME}/.cache/brightness-control-cache"
|
||
|
|
||
|
notify-brightness() {
|
||
|
brightness="$(brightnessctl -m | sed 's/,/ /g' | awk '{print $4}' | tr -d '\n' | tr -d '%')"
|
||
|
notify-send -h string:x-canonical-private-synchronous:brightness-control-sh -t 4000 -u normal -a "Brightness" -h int:value:"$brightness" "$brightness%"
|
||
|
}
|
||
|
|
||
|
save-brightness() {
|
||
|
brightness="$(brightnessctl -m | sed 's/,/ /g' | awk '{print $4}' | tr -d '\n' | tr -d '%')"
|
||
|
printf '%d' "${brightness}" >"${SAVE_FILE}"
|
||
|
}
|
||
|
|
||
|
restore-brightness() {
|
||
|
if [ ! -e "${SAVE_FILE}" ]; then
|
||
|
echo "brightness-control.sh: error: save file at \"${SAVE_FILE}\" not found" >&2
|
||
|
exit 1
|
||
|
fi
|
||
|
brightness="$(cat "${SAVE_FILE}")"
|
||
|
brightnessctl s "${brightness}%"
|
||
|
}
|
||
|
|
||
|
print-usage() {
|
||
|
echo 'usage: brightness-control.sh [up|down|set|restore|display] <ammount>' 1>&2
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
if [ "$#" -lt 1 ]; then
|
||
|
print-usage
|
||
|
fi
|
||
|
|
||
|
ammount='5%'
|
||
|
value='50%'
|
||
|
if [ "${#}" -gt 1 ]; then
|
||
|
ammount="${2}"
|
||
|
value="${2}"
|
||
|
fi
|
||
|
|
||
|
case "${1}" in
|
||
|
'up')
|
||
|
brightnessctl s "+${ammount}" > /dev/null
|
||
|
notify-brightness
|
||
|
save-brightness
|
||
|
;;
|
||
|
'down')
|
||
|
brightnessctl s "${ammount}-" > /dev/null
|
||
|
notify-brightness
|
||
|
save-brightness
|
||
|
;;
|
||
|
'set')
|
||
|
brightnessctl s "${value}" > /dev/null
|
||
|
notify-brightness
|
||
|
save-brightness
|
||
|
;;
|
||
|
'display')
|
||
|
notify-brightness
|
||
|
;;
|
||
|
'restore')
|
||
|
restore-brightness
|
||
|
;;
|
||
|
*)
|
||
|
print-usage
|
||
|
;;
|
||
|
esac
|