#!/bin/zsh ([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return zmodload zsh/mathfunc typeset -A icons typeset -A colors icons=([c]='' [lc]='' [hc]='' [s]='🌢' [lr]='🌢' [hr]='' [sn]='' [t]='' [h]='' [sl]='') colors=([c]="yellow" [lc]="yellow" [hc]="cyan" [s]="yellow" [lr]="cyan" [hr]="blue" [t]="white" [h]="white" [sl]="blue" [sn]="white") result=$(curl -sL https://www.metaweather.com/api/location/${1:-1339615}/ | jq -e '.consolidated_weather[0] | {"temp": .the_temp, "hum": .humidity, "icon": .weather_state_abbr}') if [ ! -z $result ]; then ico=$(<<< "$result" jq -r '.icon') <<< "$(( int(rint($(jq -r '.temp' <<< $result))) )) ${colors[$ico]:-white} ${icons[$ico]:-X} $(( int(rint($(jq -r '.hum' <<< $result))) ))" > ${2:-~/.cache/weather} fi