ZSHFiles/custom/segments/cprompts:cache:async:weather

9 lines
449 B
Plaintext

local REPLY
zstyle -s ':custom:prompts:weather' location REPLY
local result=$(curl -sL https://www.metaweather.com/api/location/${REPLY:-1339615}/ | jq -e '.consolidated_weather[0] | {"temp": .the_temp, "icon": .weather_state_abbr}')
if [ ! -z $result ]; then
local ico=$(print $result | jq -r '.icon')
typeset -g _cprompts_weather=($(print $result | jq -r '.temp') ${colors[$ico]} ${icons[$ico]:-?})
print ${_cprompts_weather%%.*} > $tmpfile
fi