ZSHFiles/custom/segments.zsh

69 lines
2.2 KiB
Bash
Raw Normal View History

typeset -gi _mail_count
2020-04-06 21:30:24 +00:00
function prompt_docker_host() {
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() {
[ -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
}
function prompt_covid_19() {
local tmpfile=~/.cache/covidres
local -a stats
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
fi
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}"
}