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

9 lines
454 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=($(jq -r '.temp' <<< $result) ${colors[$ico]:-white} ${icons[${ico:-X}]})
print ${_cprompts_weather%%.*} > $tmpfile
fi