From d2b62c9d6f30a0ea88b2a235cde120cd10ba332b Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Sat, 11 Jul 2026 22:14:43 -0400 Subject: Sketchybar now, got tired of the battery issue --- .../sketchybar/bar-config/plugins/weather.sh | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 users/ryan/modules/sketchybar/bar-config/plugins/weather.sh (limited to 'users/ryan/modules/sketchybar/bar-config/plugins/weather.sh') diff --git a/users/ryan/modules/sketchybar/bar-config/plugins/weather.sh b/users/ryan/modules/sketchybar/bar-config/plugins/weather.sh new file mode 100755 index 0000000..abf8103 --- /dev/null +++ b/users/ryan/modules/sketchybar/bar-config/plugins/weather.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# custom/weather -> condition icon + temp, with a hover popup ("tooltip"). +# Uses wttr.in JSON (format=j2, the smaller no-hourly variant). Needs jq + curl. +source "$CONFIG_DIR/colors.sh" +source "$CONFIG_DIR/icons.sh" + +CACHE="/tmp/sketchybar_weather.txt" + +# --- hover: show/hide the popup, populated from the cached line --- +case "$SENDER" in + mouse.entered) + [ -f "$CACHE" ] && sketchybar --set weather.details label="$(cat "$CACHE")" + sketchybar --set "$NAME" popup.drawing=on + exit 0 ;; + mouse.exited) + sketchybar --set "$NAME" popup.drawing=off + exit 0 ;; +esac + +command -v jq >/dev/null 2>&1 || { sketchybar --set "$NAME" label="wttr?"; exit 0; } + +JSON="$(curl -sf --max-time 6 'wttr.in/?format=j2')" \ + || JSON="$(curl -sf --max-time 6 'wttr.in/?format=j1')" \ + || { sketchybar --set "$NAME" label="--"; exit 0; } + +cc() { printf '%s' "$JSON" | jq -r ".current_condition[0].$1 // empty"; } +CODE="$(cc weatherCode)"; TEMP="$(cc temp_F)"; FEELS="$(cc FeelsLikeF)" +HUM="$(cc humidity)"; WSPD="$(cc windspeedMiles)"; WDIR="$(cc winddir16Point)" +DESC="$(printf '%s' "$JSON" | jq -r '.current_condition[0].weatherDesc[0].value // empty')" +AREA="$(printf '%s' "$JSON" | jq -r '.nearest_area[0].areaName[0].value // empty')" + +# daytime? simple local-hour heuristic (06:00–18:59) for clear/partly-cloudy variants +HOUR=$(date +%H); HOUR=${HOUR#0}; : "${HOUR:=0}" +if [ "$HOUR" -ge 6 ] && [ "$HOUR" -lt 19 ]; then DAY=1; else DAY=0; fi + +# WWO weatherCode -> nf-weather glyph +case "$CODE" in + 113) [ "$DAY" = 1 ] && ICON="$WEA_SUNNY" || ICON="$WEA_NIGHT" ;; + 116) [ "$DAY" = 1 ] && ICON="$WEA_DAY_CLOUDY" || ICON="$WEA_NIGHT_CLOUDY" ;; + 119|122) ICON="$WEA_CLOUDY" ;; + 143|248|260) ICON="$WEA_FOG" ;; + 200|386|389|392|395) ICON="$WEA_THUNDER" ;; + 176|263|266|293|296|353) ICON="$WEA_SHOWERS" ;; + 299|302|305|308|356|359) ICON="$WEA_RAIN" ;; + 179|227|230|323|326|329|332|335|338|368|371) ICON="$WEA_SNOW" ;; + 182|185|281|284|311|314|317|320|350|362|365|374|377) ICON="$WEA_SLEET" ;; + *) ICON="$WEA_CLOUDY" ;; +esac + +[ -z "$TEMP" ] && exit 0 + +# bar: °F (drop " ${TEMP}°F" if you want the icon only) +sketchybar --set "$NAME" label="$ICON ${TEMP}°F" + +# cache the single-line hover tooltip +printf '%s' "${AREA:+$AREA · }${DESC} · feels ${FEELS}°F · ${HUM}% humidity · ${WDIR} ${WSPD}mph" > "$CACHE" -- cgit v1.3