Move async fetches to misc-scritps and remove uircd temporarily

This commit is contained in:
Alex D. 2020-11-06 18:17:43 +01:00
parent 6aefab8d78
commit d28d45391e
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
9 changed files with 11 additions and 78 deletions

View File

@ -1,4 +0,0 @@
local REPLY
zstyle -s ':custom:prompts:covid' country REPLY
typeset -g _cprompts_covid=($(curl -sL https://api.covid19api.com/country/${REPLY:-germany} | jq -e '. |= sort_by (.Date) | .[-1,-2].Active'))
[ ! -z $_cprompts_covid[1] ] && <<< ${_cprompts_covid} > $tmpfile

View File

@ -1,12 +0,0 @@
setopt local_options shwordsplit
local count=0
for f in $feedpath/*; do
local IFS=$'\n'
local content=($(< $f))
for l in ${content[@]}; do
local IFS=$'\t'
local options=($l)
[[ ${options[6]:0:9} == "yt:video:" ]] && [ $options[1] -gt $(($epochtime[1] - 14400)) ] && ((count++))
done
done
print $count > $tmpfile

View File

@ -1,12 +0,0 @@
local -A icons
local -A colors
icons=([c]='' [lc]='' [hc]='' [s]='🌢' [lr]='🌢' [hr]='' [sn]='' [t]='' [h]='' [sl]='')
colors=([c]="yellow" [lc]="yellow" [hc]="cyan" [s]="yellow" [lr]="cyan" [hr]="blue" [t]="white" [h]="white" [sl]="blue" [sn]="white")
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, "hum": .humidity, "icon": .weather_state_abbr}')
if [ ! -z $result ]; then
local ico=$(print $result | jq -r '.icon')
typeset -g _cprompts_weather=($(( int(rint($(jq -r '.temp' <<< $result))) )) ${colors[$ico]:-white} ${icons[${ico:-X}]} $(( int(rint($(jq -r '.hum' <<< $result))) )))
print ${_cprompts_weather} > $tmpfile
fi

View File

@ -1,11 +1,4 @@
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
local tmpfile=${CACHEPATH}/covid
local -a stats
zstat -A stats +mtime -- $tmpfile 2>/dev/null
if [ ${stats[1]:-0} -lt $(($epochtime[1]-43200)) ]; then
cprompts:cache:async:covid &!
else
typeset -g _cprompts_covid=($(< $tmpfile))
fi
local tmpfile=${CACHEPATH:-~/.cache}/covid
[ -r "$tmpfile" ] || return
typeset -g _cprompts_covid=($(< $tmpfile))
[ -v _cprompts_covid ] && p10k segment -b red -i '' -t "${_cprompts_covid[1]:-unknown} ($(( ${_cprompts_covid[1]:-0} - ${_cprompts_covid[2]:-0} )))"

View File

@ -1,11 +1,4 @@
setopt local_options nomatch
local tmpfile=$CACHEPATH/rss
local feedpath=~/.sfeed/feeds/
[ -r $feedpath ] || return
local -a cache
zstat -A cache +mtime -- $tmpfile 2>/dev/null
([ ! -v _cprompts_sfeed ] || [ ${cache[1]:-0} -lt $(($epochtime[1] - 300)) ]) && cprompts:cache:async:rss &!
local tmpfile=${CACHEPATH:-~/.cache}/rss
[ -r $tmpfile ] || return
typeset -g _cprompts_sfeed=$(< $tmpfile)
[ ${_cprompts_sfeed:-0} -ne 0 ] && p10k segment -b red -i '' -t "+${_cprompts_sfeed:-unknown}"

View File

@ -1,10 +1,6 @@
local cachefile=~/.cache/twitch
local cachefile=${CACHEPATH:-~/.cache}/twitch
[ -r $cachefile ] || return
local -a stats
zstat -A stats +mtime -- $cachefile 2>/dev/null
if [ "${_cprompts_twitch[2]:-1}" -ne "${stats[1]:-0}" ]; then
local IFS=$'\n'
local streaming=($(< $cachefile))
typeset -g _cprompts_twitch=(${#streaming} $stats[1])
fi
local IFS=$'\n'
local streaming=($(< $cachefile))
typeset -g _cprompts_twitch=(${#streaming} $stats[1])
[ ${_cprompts_twitch[1]} -gt 0 ] && p10k segment -b purple -i '' -t "${_cprompts_twitch[1]:-unknown}"

View File

@ -1,14 +0,0 @@
local REPLY
local NICK
zstyle -s ':custom:prompts:uircd' nick NICK
zstyle -s ':custom:prompts:uircd' glob REPLY
local files=(${~REPLY}(.N))
local filtered=()
for i in $files; do
local IFS=$'\n'
local lines=($(tail -n100 $i))
filtered+=( ${(M)lines:#@time=$(date '+%F')* PRIVMSG * :*${NICK}*} )
done
typeset -g _cprompts_mentions_count=${#${(u)filtered}}
[[ ${_cprompts_mentions_count} -gt 0 ]] || return
p10k segment -b red -i '' -t "${_cprompts_mentions_count:-unknown}"

View File

@ -1,11 +1,4 @@
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
local tmpfile=$CACHEPATH/weather
local -a stats
zstat -A stats +mtime -- $tmpfile 2>/dev/null
if [ ${stats[1]:-0} -lt $(($epochtime[1]-3600)) ]; then
cprompts:cache:async:weather &!
else
typeset -g _cprompts_weather=($(< $tmpfile))
fi
[ -r "$tmpfile" ] || return
typeset -g _cprompts_weather=($(< $tmpfile))
[ -v _cprompts_weather ] && p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}°C ${_cprompts_weather[4]:-unk}%%"

View File

@ -32,7 +32,7 @@ fi
zstyle -s ':custom:preferences' prompt _cur_prompt
if [[ $_cur_prompt == "p9k" ]] && [[ -r "${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme" ]]; then
fpath+=("${ZDOTDIR}/powerlevel-config/segments")
function {prompt_c_{covid_19,docker_host,mpv,new_mail,todo,weather,newsboat,mumble,sfeed,uircd,twitch},cprompts:cache:async:{covid,weather,rss}}() {
function prompt_c_{covid_19,docker_host,mpv,new_mail,todo,weather,newsboat,mumble,sfeed,twitch}() {
autoload -X
}
source ${ZDOTDIR}/powerlevel-config/command.zsh