diff options
author | Baitinq <30861839+Baitinq@users.noreply.github.com> | 2021-11-18 17:56:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-18 17:56:56 +0000 |
commit | d188a68ee5d60e295b89fab16ebf40bdeee88e9c (patch) | |
tree | 08bb338408240615db2d9ae1e04589ab3fdd0352 | |
download | smart-greyscale-d188a68ee5d60e295b89fab16ebf40bdeee88e9c.tar.gz smart-greyscale-d188a68ee5d60e295b89fab16ebf40bdeee88e9c.tar.bz2 smart-greyscale-d188a68ee5d60e295b89fab16ebf40bdeee88e9c.zip |
Add files via upload
-rw-r--r-- | smart_greyscale.sh | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/smart_greyscale.sh b/smart_greyscale.sh new file mode 100644 index 0000000..2aff820 --- /dev/null +++ b/smart_greyscale.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Requires redshift and picom + +period=300 +location="" + +trap cleanup EXIT + +cleanup() +{ + killall picom 2> /dev/null +} + +check_if_picom_already_running() +{ + if pgrep -x "picom" > /dev/null + then + echo "PICOM IS ALREADY RUNNING, PLEASE KILL IT AND EXECUTE THE SCRIPT AGAIN." + exit 1 + fi +} + +check_and_enable_if_night_or_day() +{ + if redshift -l $location -p | grep -i -q "day"; then + killall picom + else + if ! pgrep -x "picom" > /dev/null; then + picom -b --config /dev/null --backend glx --glx-fshader-win "uniform sampler2D tex; uniform float opacity; void main() { vec4 c = texture2D(tex, gl_TexCoord[0].xy); float y = dot(c.rgb, vec3(0.2126, 0.7152, 0.0722)); gl_FragColor = opacity*vec4(y, y, y, c.a); }" & + fi + fi +} + +while getopts ':l:p:' flag; do + case "${flag}" in + l) location="${OPTARG}" ;; + p) period="${OPTARG}" ;; + esac +done + +main() +{ + if [ "$location" == "" ]; then + echo "Need location argument [-l (LAT:LON)]" + exit 1 + fi + + check_if_picom_already_running + + while true + do + check_and_enable_if_night_or_day + + sleep $period + done +} + +main |