Skip to content

Instantly share code, notes, and snippets.

@michaelmrose
Last active October 8, 2023 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelmrose/d511d25e7fe166a9ec1b5c0d0ffddbcc to your computer and use it in GitHub Desktop.
Save michaelmrose/d511d25e7fe166a9ec1b5c0d0ffddbcc to your computer and use it in GitHub Desktop.
basic redshift like implimentation with bash
#!/bin/bash
monitors=$(xrandr --listactivemonitors | tail -n +2 | awk '{print $4}')
# Get the current hour
if [ "$#" -eq 1 ]; then
current_hour="$1"
else
current_hour=$(date +%H)
fi
# define what hours we use to decide when to shift
morning=6
evening=20
night=23
# Define the gamma values
gamma_normal="1.0:1.0:1.0"
gamma_red_start="1.0:1.0:1.0"
gamma_red_end="0.95:0.8:0.7"
# Function to interpolate between two values
interpolate() {
echo "$(awk "BEGIN {print $1 + ($2 - $1) * ($3/6)}")"
}
# Check the time and adjust gamma accordingly
if (( current_hour >= $morning && current_hour < $evening )); then
for monitor in $monitors; do
xrandr --output $monitor --gamma $gamma_normal
done
elif (( current_hour >= $evening && current_hour < $night )); then
# Calculate how far into the 2PM-8PM period we are, in hours
hours_into_period=$(( current_hour - $evening ))
# Interpolate gamma values
red=$(interpolate $(echo $gamma_red_start | cut -d: -f1) $(echo $gamma_red_end | cut -d: -f1) $hours_into_period)
green=$(interpolate $(echo $gamma_red_start | cut -d: -f2) $(echo $gamma_red_end | cut -d: -f2) $hours_into_period)
blue=$(interpolate $(echo $gamma_red_start | cut -d: -f3) $(echo $gamma_red_end | cut -d: -f3) $hours_into_period)
for monitor in $monitors; do
xrandr --output $monitor --gamma "$red:$green:$blue"
done
else
for monitor in $monitors; do
xrandr --output $monitor --gamma $gamma_red_end
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment