From dd7868e732e965e863b0ac38afc63eca210b1130 Mon Sep 17 00:00:00 2001 From: Samuel O'Neal Date: Sun, 13 Sep 2026 00:25:32 -0600 Subject: [PATCH] added more advance weather capabilities --- hyprland/.local/bin/weather-forecast.sh | 14 +++++++ hyprland/.local/bin/weather.sh | 39 ++++++++++++-------- monique/.config/monique/profiles/laptop.json | 2 +- waybar/.config/waybar/config.jsonc | 6 ++- 4 files changed, 42 insertions(+), 19 deletions(-) create mode 100755 hyprland/.local/bin/weather-forecast.sh diff --git a/hyprland/.local/bin/weather-forecast.sh b/hyprland/.local/bin/weather-forecast.sh new file mode 100755 index 0000000..9e6e5b9 --- /dev/null +++ b/hyprland/.local/bin/weather-forecast.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Open the hourly weather forecast (wttr.in v2 view) in a ghostty window; +# focus it if it is already open. Intended as the on-click action for the +# waybar weather module. +set -uo pipefail + +if hyprctl clients -j 2>/dev/null | jq -e 'any(.[]; ((.title // "") + " " + (.class // "")) | ascii_downcase | contains("wttr"))' >/dev/null 2>&1; then + hyprctl dispatch 'hl.dsp.focus({ window = "title:wttr" })' 2>/dev/null || true + exit 0 +fi + +CITY="${WEATHER_CITY:-Denver}" +ghostty --title=wttr -e bash -c 'curl -fsS --max-time 15 "https://v2.wttr.in/'"${CITY}"'"; printf "\n"; read -r -p "Press Enter to close"' & +disown \ No newline at end of file diff --git a/hyprland/.local/bin/weather.sh b/hyprland/.local/bin/weather.sh index c8beced..ae4cfc4 100755 --- a/hyprland/.local/bin/weather.sh +++ b/hyprland/.local/bin/weather.sh @@ -1,17 +1,19 @@ #!/usr/bin/env bash -# Print the current weather as a short icon+temp string, e.g. "🌦️ +83°F". -# Caches the wttr.in response so the lock screen and waybar don't hit the -# network on every refresh. A cached value is served immediately -- even when +# Print the current weather as a short icon+temp string, e.g. "🌦️ +83°F", +# plus -- in --json mode (for waybar) a multi-line "current conditions" +# tooltip. A single cached wttr.in response is served immediately -- even when # stale -- and refreshed in the background, so a slow network never delays the -# lock screen's first frame. Override the location with WEATHER_CITY or edit -# CITY below. +# lock screen's first frame or waybar's tooltip. Override the location with +# WEATHER_CITY or edit CITY below. set -u CITY="${WEATHER_CITY:-Denver}" CACHE_DIR="${XDG_RUNTIME_DIR:-/tmp}" CACHE="${CACHE_DIR}/wttr.cache" CACHE_MAX_AGE=1800 # 30 minutes -URL="https://wttr.in/${CITY}?format=%c+%t" +# First line is the waybar text; the following lines are the hover tooltip. +FORMAT='%c+%t%5Cn%5Cn%C%5CnTemperature:+%t+%28feels+like+%f%29%5CnHumidity:+%h%5CnWind:+%w%5CnPrecipitation:+%p%5CnPressure:+%P%5CnUV+index:+%u' +URL="https://wttr.in/${CITY}?format=${FORMAT}" fetch() { TMP="${CACHE}.tmp.$$" @@ -24,25 +26,30 @@ fetch() { fi } -# Fresh cache: print it. +# Fresh cache: use it as-is. if [ -f "${CACHE}" ] && [ "$(( $(date +%s) - $(stat -c %Y "${CACHE}") ))" -lt "${CACHE_MAX_AGE}" ]; then - cat "${CACHE}" - exit 0 -fi - -# Stale cache: print it immediately, then refresh in the background so the + BODY="$(cat "${CACHE}")" +# Stale cache: use it immediately, then refresh in the background so the # caller never blocks. flock keeps a pile-up of refreshes from several clients # (lock screen, waybar) from running concurrent curls. -if [ -f "${CACHE}" ]; then - cat "${CACHE}" +elif [ -f "${CACHE}" ]; then + BODY="$(cat "${CACHE}")" ( exec 9>"${CACHE}.lock" flock -n 9 || exit 0 fetch >/dev/null 2>&1 ) & disown +# No cache at all: fetch synchronously, but with tight timeouts. +else + BODY="$(fetch)" +fi + +if [ "${1:-text}" = "--json" ]; then + TEXT="$(printf '%s' "${BODY}" | head -n 1)" + TOOLTIP="$(printf '%s' "${BODY}" | tail -n +2)" + jq -nc --arg text "${TEXT}" --arg tip "${TOOLTIP}" '{text: $text, tooltip: $tip}' exit 0 fi -# No cache at all: fetch synchronously, but with tight timeouts. -fetch +printf '%s' "${BODY}" | head -n 1 diff --git a/monique/.config/monique/profiles/laptop.json b/monique/.config/monique/profiles/laptop.json index a2e00f3..96928ff 100644 --- a/monique/.config/monique/profiles/laptop.json +++ b/monique/.config/monique/profiles/laptop.json @@ -56,5 +56,5 @@ } ], "workspace_rules": [], - "last_applied_time": 1789241254.0499482 + "last_applied_time": 1789279298.6281931 } diff --git a/waybar/.config/waybar/config.jsonc b/waybar/.config/waybar/config.jsonc index 3c57391..46b1719 100644 --- a/waybar/.config/waybar/config.jsonc +++ b/waybar/.config/waybar/config.jsonc @@ -30,9 +30,11 @@ }, "custom/weather": { "format": "{}", - "exec": "~/.local/bin/weather.sh", + "exec": "~/.local/bin/weather.sh --json", + "return-type": "json", "interval": 600, - "tooltip": false + "tooltip": true, + "on-click": "~/.local/bin/weather-forecast.sh" }, "tray": { "icon-size": 16,