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:29:44 +00:00
|
|
|
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}"
|
2020-04-06 21:30:24 +00:00
|
|
|
}
|
2020-05-22 22:02:16 +00:00
|
|
|
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}"
|
|
|
|
}
|
2020-04-14 18:09:10 +00:00
|
|
|
function prompt_covid_19() {
|
2020-05-19 12:29:44 +00:00
|
|
|
local tmpfile=${CACHEPATH}/covid
|
2020-04-14 18:09:10 +00:00
|
|
|
local -a stats
|
2020-05-19 12:29:44 +00:00
|
|
|
if [ ! -v _cprompts_covid ]; then
|
2020-05-19 12:11:34 +00:00
|
|
|
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
|
|
|
if [[ $stats[1] < $(($epochtime[1]-86400)) ]]; then
|
2020-05-22 22:02:16 +00:00
|
|
|
typeset -g _cprompts_covid=$(curl -sL https://api.covid19api.com/country/germany | jq -e '. |= sort_by (.Date) | .[-1].Active')
|
2020-05-19 12:11:34 +00:00
|
|
|
[ ! -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() {
|
2020-05-19 12:29:44 +00:00
|
|
|
local tmpfile=${CACHEPATH}/weather
|
2020-05-19 12:11:34 +00:00
|
|
|
local -a stats
|
|
|
|
|
|
|
|
# Fancy stuff
|
|
|
|
local -A icons
|
|
|
|
local -A colors
|
2020-05-21 23:15:13 +00:00
|
|
|
icons[c]='盛'
|
2020-05-19 12:11:34 +00:00
|
|
|
colors[c]="yellow"
|
2020-05-21 23:15:13 +00:00
|
|
|
icons[lc]=''
|
2020-05-19 12:11:34 +00:00
|
|
|
colors[lc]="yellow"
|
2020-05-21 23:15:13 +00:00
|
|
|
icons[hc]=''
|
2020-05-19 12:11:34 +00:00
|
|
|
colors[hc]="cyan"
|
2020-05-21 23:15:13 +00:00
|
|
|
icons[s]='🌢'
|
|
|
|
colors[s]="yellow"
|
|
|
|
icons[lr]='🌢'
|
2020-05-19 12:11:34 +00:00
|
|
|
colors[lr]="cyan"
|
2020-05-21 23:15:13 +00:00
|
|
|
icons[hr]=''
|
|
|
|
colors[hr]="blue"
|
|
|
|
icons[t]=''
|
2020-05-19 12:11:34 +00:00
|
|
|
colors[t]="white"
|
2020-05-21 23:15:13 +00:00
|
|
|
icons[h]=''
|
|
|
|
colors[h]="white"
|
|
|
|
icons[sl]=''
|
2020-05-19 12:11:34 +00:00
|
|
|
colors[sl]="blue"
|
|
|
|
icons[sn]=''
|
|
|
|
colors[sn]="white"
|
|
|
|
|
2020-05-19 12:29:44 +00:00
|
|
|
if [ ! -v _cprompts_weather ]; then
|
2020-05-19 12:11:34 +00:00
|
|
|
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
2020-05-21 23:15:13 +00:00
|
|
|
if [[ $stats[1] < $(($epochtime[1]-21600)) ]]; then
|
2020-05-19 12:11:34 +00:00
|
|
|
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')
|
2020-05-19 12:29:44 +00:00
|
|
|
typeset -g _cprompts_weather=($(print $result | jq -r '.temp') ${colors[$ico]} ${icons[$ico]:-?})
|
2020-05-19 12:11:34 +00:00
|
|
|
print $_cprompts_weather > $tmpfile
|
|
|
|
fi
|
|
|
|
else
|
2020-05-19 12:29:44 +00:00
|
|
|
typeset -g _cprompts_weather=($(< $tmpfile))
|
2020-05-19 12:11:34 +00:00
|
|
|
fi
|
|
|
|
fi
|
2020-05-19 12:29:44 +00:00
|
|
|
p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}"
|
2020-04-14 18:09:10 +00:00
|
|
|
}
|
2020-05-21 20:31:48 +00:00
|
|
|
|
|
|
|
function prompt_mpv_mpris() {
|
|
|
|
typeset -g _cprompts_mpv
|
2020-05-22 22:02:16 +00:00
|
|
|
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 ...)"
|
2020-05-21 20:31:48 +00:00
|
|
|
}
|