#!/bin/sh WTTR_URL="${WTTR_URL:-wttr.in}" REPORT_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/wttr-report" UPDATE_INTERVAL_SECONDS=1800 notify() { notify-send "${0##*/}" "$@" } is_report_old() { current_time="$(date +'%s')" report_file_time="$(date -r "$REPORT_FILE" +'%s')" [ "$((current_time - report_file_time))" -ge "$UPDATE_INTERVAL_SECONDS" ] } if [ ! -f "$REPORT_FILE" ] || is_report_old; then curl -s "$WTTR_URL?format=%C\n%t\n" >"$REPORT_FILE" notify "Fetched new weather report." fi i=0 while IFS= read -r line; do case "$i" in 0) conditions="${line%[[:space:]]}" ;; 1) temperature="${line#+}" ;; esac i=$((i + 1)) done <"$REPORT_FILE" printf '%s (%s)\n' "$conditions" "$temperature"