function prompt_c_docker_host() { p10k segment -b blue -i '' -t "${DOCKER_HOST#*://}" -c "${DOCKER_HOST#*://}" } typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker' function prompt_c_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_c_youtube() { [ -v commands\[sqlite3\] ] || return 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_c_covid_19() { ([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return local tmpfile=${CACHEPATH}/covid local REPLY zstyle -s ':custom:prompts:covid' country REPLY local -a stats if [ ! -v _cprompts_covid ]; then zstat -A stats +mtime -- $tmpfile 2>/dev/null if [[ $stats[1] < $(($epochtime[1]-86400)) ]]; then cprompts:cache:async:covid &! else typeset -g _cprompts_covid=$(< $tmpfile) fi fi [ -v _cprompts_covid ] && p10k segment -b red -i '' -t "${_cprompts_covid:-unknown}" } function cprompts:cache:async:covid() { typeset -g _cprompts_covid=$(curl -sL https://api.covid19api.com/country/${REPLY:-germany} | jq -e '. |= sort_by (.Date) | .[-1].Active') [ ! -z $_cprompts_covid ] && print ${_cprompts_covid} > $tmpfile } function prompt_c_weather() { ([ -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}" } function cprompts:cache:async:weather() { 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=($(print $result | jq -r '.temp') ${colors[$ico]} ${icons[$ico]:-?}) print ${_cprompts_weather%%.*} > $tmpfile fi } function prompt_c_mpv_mpris() { ([ -v commands\[busctl\] ] && [ -v commands\[jq\] ]) || return 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 ] && return _cprompts_mpv="$(print $busout | jq -er '(.data."xesam:title".data // empty)')" [ -z $_cprompts_mpv ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv:0:20}$([ ${#_cprompts_mpv} -gt 20 ] && print ...)" } function prompt_c_todo() { [ -r todo.txt ] || return local -a stats zstat -A stats +mtime -- todo.txt 2>/dev/null if [ ! -v _cprompts_todo ] || [ $_cprompts_todo[4] -ne $stats[1] ]; then local todofi=(${(f@)${mapfile[todo.txt]}}) local t_nf=0 local t_f=0 local colors=(red yellow green) for i in $todofi; do [ ${i:0:1} = "-" ] && ((t_nf++)) [ ${i:0:1} = "+" ] && ((t_f++)) done local t_tot=$(($t_f+$t_nf)) [ $t_tot -gt 0 ] || return typeset -g _cprompts_todo=($t_f $t_tot ${colors[$(( 1+int( $t_f / $t_tot.0 * 2 ) ))]} $stats[1]) fi p10k segment -b ${_cprompts_todo[3]:-white} -i '' -t "${_cprompts_todo[1]:-unknown} / ${_cprompts_todo[2]:-unknown}" }