function prompt_docker_host() { p10k segment -b blue -i '' -t "${DOCKER_HOST#*://}" -c "${DOCKER_HOST#*://}" } typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker' function prompt_new_mail() { if [ ! -v _cprompts_mail_count ]; then local new_mails=(~/Mail/*/Inbox/new/*(.N)) typeset -g _cprompts_mail_count=${#new_mails} fi [[ ${_cprompts_mail_count} -gt 0 ]] || return p10k segment -b yellow -i '' -t "${_cprompts_mail_count:-unknown}" } function prompt_youtube() { local newsboatdb=~/.newsboat/cache.db if [ ! -v _cprompts_youtube ]; then typeset -g _cprompts_youtube="$(sqlite3 ${newsboatdb} --ascii 'SELECT COUNT(id) FROM rss_item WHERE unread == 1 AND guid GLOB "yt:video:*"')" fi p10k segment -b red -i '' -t "${_cprompts_youtube}" } function prompt_covid_19() { local tmpfile=${CACHEPATH}/covid 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 | jq -e '. |= sort_by (.Date) | .[-1].Active') [ ! -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=${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 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') typeset -g _cprompts_weather=($(print $result | jq -r '.temp') ${colors[$ico]} ${icons[$ico]:-?}) print $_cprompts_weather > $tmpfile fi else typeset -g _cprompts_weather=($(< $tmpfile)) fi fi p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}" } function prompt_mpv_mpris() { typeset -g _cprompts_mpv local busout="$(busctl get-property -j --no-pager --timeout=300ms --user org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Metadata 2>/dev/null)" [ -z $busout ] || _cprompts_mpv="$(print $busout | jq -er '.data."xesam:title".data // empty')" [ -z $_cprompts_mpv ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv:0:25}$([ ${#_cprompts_mpv} -gt 25 ] && print ...)" }