From 0c6fc94a5459b377d46a17e85893eaede4b81a11 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 6 Apr 2018 09:46:50 -0400 Subject: [PATCH] screen/weather: Show snow status as bg color --- screen/weather | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/screen/weather b/screen/weather index 0d6cad4..e3d0043 100755 --- a/screen/weather +++ b/screen/weather @@ -29,11 +29,7 @@ export -n HTTP_PROXY http_proxy # fall back to realtime weather data if no cache is available wdata=/tmp/.weather data="$( - if [ -s "$wdata" ]; then - cat /tmp/.weather - else - weather -i "${WEATHER_METAR:-kbuf}" - fi \ + cat /tmp/.weather 2>/dev/null \ | sed 's/^ \+//g' )" @@ -48,6 +44,12 @@ weather_c="$( echo "$weather_temp" \ | grep -oP '[0-9\.-]+ C' \ | cut -d' ' -f1 \ )" +# filters out e.g. "N inches of snow on ground" +weather_type="$( echo "$data" \ + | grep '^Weather: ' \ + | grep -v ' on ground' \ + | cut -d' ' -f2- \ +)" wind="$( grep -o '[0-9]\+ MPH' <<< "$data" \ | tr '\n' '-' \ | sed 's/-$//;s/ \?MPH-/-/' \ @@ -70,10 +72,15 @@ else color=m # purple with my color scheme fi +bgcolor='.' +if [[ "$weather_type" =~ snow ]]; then + bgcolor=w +fi + # if it's sunny, make the status brighter echo "$data" | grep -qP 'sunny|(mostly )?clear|partly cloudy' && { color=$( echo $color | tr '[:lower:]' '[:upper:]' ) } -echo -e "\005{+ .$color}${weather_f}F/${weather_c}C $wind\005{-}" +echo -e "\005{+ $bgcolor$color}${weather_f}F/${weather_c}C $wind\005{-}"