#!/usr/bin/env bash LAT="26.4187" LON="-81.4173" WX_FILE="/dev/shm/wx.txt" LAST_CHIME="" CLOCK_PID="" # Remap ANSI yellow (index 3 & 11) to P3 Amber Phosphor on Linux console printf '\033]P3FFB000\033]PBFFCC33' play_westminster() { local m="$1" h12="$2" case "$m" in 15) beep -f 830.61 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 659.25 -l 320 -n -D 50 -f 493.88 -l 640 ;; 30) beep -f 659.25 -l 320 -n -D 50 -f 830.61 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 493.88 -l 640 \ -n -D 100 -f 659.25 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 830.61 -l 320 -n -D 50 -f 659.25 -l 640 ;; 45) beep -f 830.61 -l 320 -n -D 50 -f 659.25 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 493.88 -l 640 \ -n -D 100 -f 493.88 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 830.61 -l 320 -n -D 50 -f 659.25 -l 640 \ -n -D 100 -f 830.61 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 659.25 -l 320 -n -D 50 -f 493.88 -l 640 ;; 00) beep -f 659.25 -l 320 -n -D 50 -f 830.61 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 493.88 -l 640 \ -n -D 100 -f 659.25 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 830.61 -l 320 -n -D 50 -f 659.25 -l 640 \ -n -D 100 -f 830.61 -l 320 -n -D 50 -f 659.25 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 493.88 -l 640 \ -n -D 100 -f 493.88 -l 320 -n -D 50 -f 739.99 -l 320 -n -D 50 -f 830.61 -l 320 -n -D 50 -f 659.25 -l 640 for _ in $(seq 1 "$h12"); do beep -D 400 -f 415.30 -l 950 done ;; esac } refresh_wx() { local raw temp hum raw=$(curl -fsS --max-time 5 "https://api.open-meteo.com/v1/forecast?latitude=${LAT}&longitude=${LON}¤t=temperature_2m,relative_humidity_2m&temperature_unit=fahrenheit" 2>/dev/null) || return temp=$(printf '%s' "$raw" | sed -n 's/.*"temperature_2m":\([-0-9.]*\).*/\1/p') hum=$(printf '%s' "$raw" | sed -n 's/.*"relative_humidity_2m":\([0-9.]*\).*/\1/p') if [[ -n "$temp" && -n "$hum" ]]; then printf "%.0fF | %.0f%% RH" "$temp" "$hum" > "$WX_FILE" fi } cleanup() { [[ -n "$CLOCK_PID" ]] && kill "$CLOCK_PID" 2>/dev/null tput cnorm printf '\033]R' # Reset VGA palette on exit clear exit 0 } trap cleanup INT TERM EXIT tput civis [[ -f "$WX_FILE" ]] || refresh_wx LAST_WX=$(date +%s) while true; do NOW_S=$(date +%s) if (( NOW_S - LAST_WX >= 1800 )); then refresh_wx LAST_WX=$NOW_S fi MIN=$(date +%M) SEC=$(date +%S) H12=$(date +%I | sed 's/^0//') CHIME_KEY="$(date +%Y%m%d%H%M)" if [[ ( "$MIN" == "00" || "$MIN" == "15" || "$MIN" == "30" || "$MIN" == "45" ) && "$SEC" == "00" && "$CHIME_KEY" != "$LAST_CHIME" ]]; then LAST_CHIME="$CHIME_KEY" play_westminster "$MIN" "$H12" & fi CYCLE_SEC=$(( (10#$MIN % 15) * 60 + 10#$SEC )) if (( CYCLE_SEC < 300 )); then if [[ -z "$CLOCK_PID" ]] || ! kill -0 "$CLOCK_PID" 2>/dev/null; then clear tty-clock -c -B -t -C 3 & CLOCK_PID=$! sleep 0.2 fi # Print amber weather readout below the centered clock WX_TEXT=$(cat "$WX_FILE" 2>/dev/null || echo "Weather N/A") ROWS=$(tput lines) COLS=$(tput cols) TARGET_ROW=$(( ROWS / 2 + 6 )) TARGET_COL=$(( (COLS - ${#WX_TEXT}) / 2 )) printf '\033[%d;%dH\033[1;33m%s\033[0m' "$TARGET_ROW" "$TARGET_COL" "$WX_TEXT" else if [[ -n "$CLOCK_PID" ]] && kill -0 "$CLOCK_PID" 2>/dev/null; then kill "$CLOCK_PID" 2>/dev/null wait "$CLOCK_PID" 2>/dev/null CLOCK_PID="" clear fi fi sleep 1 done