2020-04-14 18:09:10 +00:00
|
|
|
typeset -gi _mail_count
|
2020-04-06 21:30:24 +00:00
|
|
|
function prompt_docker_host() {
|
2020-04-14 18:09:10 +00:00
|
|
|
p10k segment -b blue -i '' -t "${DOCKER_HOST#*://}" -c "${DOCKER_HOST#*://}"
|
2020-04-06 21:30:24 +00:00
|
|
|
}
|
|
|
|
typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker'
|
|
|
|
function prompt_new_mail() {
|
2020-05-19 12:11:34 +00:00
|
|
|
[ -v $_cprompts_mail_count ] && typeset -g _cprompts_mail_count=(~/Mail/*/Inbox/new/*(.N))
|
|
|
|
(( ${#_cprompts_mail_count} > 0 )) || return
|
|
|
|
p10k segment -b yellow -i '' -t "${#_cprompts_mail_count:-\?}"
|
2020-04-06 21:30:24 +00:00
|
|
|
}
|
2020-04-14 18:09:10 +00:00
|
|
|
function prompt_covid_19() {
|
2020-04-16 01:02:54 +00:00
|
|
|
local tmpfile=~/.cache/covidres
|
2020-04-14 18:09:10 +00:00
|
|
|
local -a stats
|
2020-05-19 12:11:34 +00:00
|
|
|
if [ -v $_cprompts_covid ]; then
|
|
|
|
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
|
|
|
if [[ $stats[1] < $(($epochtime[1]-86400)) ]]; then
|
|
|
|
typeset -g _cprompts_covid=$(curl -sL https://api.covid19api.com/country/germany/status/confirmed/live | jq -e '. |= sort_by (.Date) | .[-1].Cases')
|
|
|
|
[ ! -z $_cprompts_covid ] && print $_cprompts_covid > $tmpfile
|
|
|
|
else
|
|
|
|
typeset -g _cprompts_covid=$(< $tmpfile)
|
|
|
|
fi
|
2020-04-14 18:09:10 +00:00
|
|
|
fi
|
2020-05-19 12:11:34 +00:00
|
|
|
p10k segment -b red -i '' -t "${_cprompts_covid:-unknown}"
|
|
|
|
}
|
|
|
|
function prompt_weather() {
|
|
|
|
local tmpfile=~/.cache/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]="cyan"
|
|
|
|
icons[lr]=''
|
|
|
|
colors[lr]="cyan"
|
|
|
|
icons[hr]=''
|
|
|
|
colors[hr]="cyan"
|
|
|
|
icons[t]=''
|
|
|
|
colors[t]="white"
|
|
|
|
icons[h]=''
|
|
|
|
colors[h]="blue"
|
|
|
|
icons[sl]=''
|
|
|
|
colors[sl]="blue"
|
|
|
|
icons[sn]=''
|
|
|
|
colors[sn]="white"
|
|
|
|
|
|
|
|
if [ -v ${_cprompts_weather[1]} ]; then
|
|
|
|
typeset -g _cprompts_weather
|
|
|
|
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
|
|
|
if [[ $stats[1] < $(($epochtime[1]-86400)) ]]; then
|
|
|
|
local result=$(curl -sL https://www.metaweather.com/api/location/${_cprompts_weather_loc:-1339615}/ | jq -e '.consolidated_weather[0] | {"temp": .the_temp, "icon": .weather_state_abbr}')
|
|
|
|
if [ ! -z $result ]; then
|
|
|
|
local ico=$(print $result | jq -r '.icon')
|
|
|
|
_cprompts_weather=($(print $result | jq -r '.temp') ${colors[$ico]} ${icons[$ico]:-?})
|
|
|
|
print $_cprompts_weather > $tmpfile
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
_cprompts_weather=($(< $tmpfile))
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
p10k segment -b ${_cprompts_weather[2]:-red} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}"
|
2020-04-14 18:09:10 +00:00
|
|
|
}
|