From 472bf7246b9d66949da3f4cfc3b5af9183cab0df Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Thu, 12 Nov 2026 19:24:15 +0100 Subject: [PATCH] xmobar: show current weather details on click Clicking the weather now runs weather.sh notify, which shows the description and temperature; the forecast keeps its ens-forecast week notification. --- .config/xmobar/weather.sh | 14 ++++++++++++-- .config/xmobar/xmobarrc_hdmi | 2 +- .config/xmobar/xmobarrc_laptop | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.config/xmobar/weather.sh b/.config/xmobar/weather.sh index 0bb2748..895b5a5 100755 --- a/.config/xmobar/weather.sh +++ b/.config/xmobar/weather.sh @@ -2,6 +2,7 @@ # Current weather for xmobar, e.g. " 7°C": NOAA's decoded METAR (the source of xmobar's Weather plugin) # Icon from the weather, else the sky conditions; clear/partly/mostly cloudy get moon icons when the sun is down. # Temperature colors match the plugin's -L 0 -H 30: low up to 0, high above 30. +# With "notify": show the description (e.g. "Light drizzle, mist") and temperature in a notification instead. STATION=LZIB LAT=48.2 LON=17.2 @@ -17,12 +18,12 @@ declare -A ICON=( report=$(curl -sf --max-time 20 https://tgftp.nws.noaa.gov/data/observations/metar/decoded/"$STATION".TXT) temp=$(sed -n 's/^Temperature: .*(\([-0-9.]*\) C).*/\1/p' <<< "$report") if [[ -z $temp ]]; then - echo "${ICON[thermometer]} N/A" + if [[ $1 == notify ]]; then notify-send "Weather" "No report from $STATION"; else echo "${ICON[thermometer]} N/A"; fi exit 0 fi # Phenomena "in the vicinity" aren't at the station; the rest are e.g. "light drizzle; mist" -wx=$(sed -n 's/^Weather: //p' <<< "$report" | tr ';' '\n' | grep -v vicinity | tr '\n' ' ') +wx=$(sed -n 's/^Weather: //p' <<< "$report" | tr ';' '\n' | sed 's/^ *//' | grep -v vicinity) wx=${wx,,} sky=$(sed -n 's/^Sky conditions: //p' <<< "$report") sky=${sky,,} @@ -66,4 +67,13 @@ if awk -v t="$temp" 'BEGIN { exit !(t > 30) }'; then color="#ffb86c" elif awk -v t="$temp" 'BEGIN { exit !(t > 0) }'; then color="#50fa7b" else color="#8be9fd" fi + +if [[ $1 == notify ]]; then + if [[ -n $wx ]]; then desc=$(paste -sd, <<< "$wx" | sed 's/,/, /g') + elif [[ $icon == day_sunny ]]; then desc=sunny + else desc=${sky:-unknown} + fi + notify-send "${ICON[$icon]} Weather" "${desc^}, $temp°C" + exit 0 +fi echo "${ICON[$icon]} $temp°C" diff --git a/.config/xmobar/xmobarrc_hdmi b/.config/xmobar/xmobarrc_hdmi index 2984304..8be140f 100644 --- a/.config/xmobar/xmobarrc_hdmi +++ b/.config/xmobar/xmobarrc_hdmi @@ -48,5 +48,5 @@ Config { overrideRedirect = True ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %multicpu% %coretemp% | %memory% |  %kbd% { %calcurse%%backup%%updates%%weather% · %ens_brief% | %pactl_volume% | %date% " + , template = "  | %UnsafeXMonadLog% } %multicpu% %coretemp% | %memory% |  %kbd% { %calcurse%%backup%%updates%%weather% · %ens_brief% | %pactl_volume% | %date% " } diff --git a/.config/xmobar/xmobarrc_laptop b/.config/xmobar/xmobarrc_laptop index 56a8b53..f4aa664 100644 --- a/.config/xmobar/xmobarrc_laptop +++ b/.config/xmobar/xmobarrc_laptop @@ -49,5 +49,5 @@ Config { overrideRedirect = True ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %multicpu% %coretemp% | %memory% |  %kbd% { %calcurse%%backup%%updates%%weather% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " + , template = "  | %UnsafeXMonadLog% } %multicpu% %coretemp% | %memory% |  %kbd% { %calcurse%%backup%%updates%%weather% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " }