ZSHFiles/custom/segments/prompt_c_weather

38 lines
875 B
Plaintext
Raw Normal View History

([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
local tmpfile=${CACHEPATH}/weather
local -a stats
# Fancy stuff
local -A icons
local -A colors
icons[c]=''
colors[c]="yellow"
icons[lc]=''
colors[lc]="yellow"
icons[hc]=''
colors[hc]="cyan"
icons[s]='🌢'
colors[s]="yellow"
icons[lr]='🌢'
colors[lr]="cyan"
icons[hr]=''
colors[hr]="blue"
icons[t]=''
colors[t]="white"
icons[h]=''
colors[h]="white"
icons[sl]=''
colors[sl]="blue"
icons[sn]=''
colors[sn]="white"
if [ ! -v _cprompts_weather ]; then
zstat -A stats +mtime -- $tmpfile 2>/dev/null
if [[ $stats[1] < $(($epochtime[1]-21600)) ]]; then
cprompts:cache:async:weather &!
else
typeset -g _cprompts_weather=($(< $tmpfile))
fi
fi
[ -v _cprompts_weather ] && p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}"