Kieran's opinionated (and probably slightly dumb) nix config
1#!/usr/bin/env bash 2 3# Function to calculate temperature based on battery percentage 4calculate_temperature() { 5 local bat_percent=$1 6 local temp 7 8 if [ "$bat_percent" -le 1 ]; then 9 temp=1000 10 elif [ "$bat_percent" -le 10 ]; then 11 # Linear interpolation between 1% (1000K) and 10% (4000K) 12 local range=$((4000 - 1000)) 13 local factor=$(( (bat_percent - 1) * 100 / 9 )) 14 temp=$(( 1000 + (range * factor) / 100 )) 15 else 16 temp=6500 # Default temperature 17 fi 18 19 echo $temp 20} 21 22# Initialize variables 23PREV_STATUS="" 24 25# Main loop 26while true; do 27 # Get battery percentage 28 battery_info=$(cat /sys/class/power_supply/BAT1/capacity) 29 percent=$(echo $battery_info | tr -d '\n') 30 31 # Check if the battery is charging 32 is_plugged=$(cat /sys/class/power_supply/BAT1/status) 33 34 # Create a status string to track changes 35 CURRENT_STATUS="${percent}_${is_plugged}" 36 37 # Only update if status has changed or first run 38 if [ "$CURRENT_STATUS" != "$PREV_STATUS" ] || [ -z "$PREV_STATUS" ]; then 39 if [ "$percent" -le 10 ] && [ "$is_plugged" != "Charging" ]; then 40 temp=$(calculate_temperature $percent) 41 hyprctl hyprsunset temperature $temp 42 else 43 # Reset to default temperature 44 hyprctl hyprsunset identity 45 fi 46 47 PREV_STATUS="$CURRENT_STATUS" 48 fi 49 50 sleep 5 51done