From d60baa543ef9f0b5ba0a1668114b00b02a1b4898 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 23 May 2020 00:02:16 +0200 Subject: [PATCH] Add youtube segment, improve covid, mpris, show few segments only if local, no dirstack --- custom/segments.zsh | 15 +++++++++++---- powerlevel-config/prompt-elements.zsh | 16 +++++++++++----- preferences.zsh | 3 +-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/custom/segments.zsh b/custom/segments.zsh index 965ad80..cc2706e 100644 --- a/custom/segments.zsh +++ b/custom/segments.zsh @@ -10,13 +10,20 @@ function prompt_new_mail() { [[ ${_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] | (.Confirmed - .Recovered)') + 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) @@ -70,7 +77,7 @@ function prompt_weather() { function prompt_mpv_mpris() { typeset -g _cprompts_mpv - _cprompts_mpv=${${"$(busctl get-property --no-pager --timeout=300ms --user org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Metadata 2>/dev/null)"##*\"xesam:title\" s \"}%%\"*} - [ -z $_cprompts_mpv ] && return - p10k segment -b magenta -i '' -t "${_cprompts_mpv:0:25}$([ ${#_cprompts_mpv} -gt 25 ] && print ...)" + 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 ...)" } diff --git a/powerlevel-config/prompt-elements.zsh b/powerlevel-config/prompt-elements.zsh index 9ed6ce4..e1aeff6 100644 --- a/powerlevel-config/prompt-elements.zsh +++ b/powerlevel-config/prompt-elements.zsh @@ -5,6 +5,7 @@ typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( disk_usage ssh root_indicator + vim_shell newline vi_mode status @@ -12,15 +13,20 @@ typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( dir_writable ) typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( - command_execution_time - background_jobs - vim_shell - new_mail +) +if [ ! -v SSH_CONNECTION ]; then +POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=( mpv_mpris + new_mail +# youtube weather covid_19 +) +fi +POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=( public_ip newline - docker_host + command_execution_time + background_jobs vcs ) diff --git a/preferences.zsh b/preferences.zsh index 058a53b..9ce3a4b 100644 --- a/preferences.zsh +++ b/preferences.zsh @@ -3,8 +3,7 @@ typeset -g CACHEPATH=/tmp typeset -g HISTSIZE=1000 typeset -g SAVEHIST=1000 typeset -g ZLE_RPROMPT_INDENT=0 -setopt appendhistory autocd auto_pushd extendedglob nomatch notify hist_ignore_all_dups hist_ignore_space nobeep - +setopt appendhistory autocd extendedglob nomatch notify hist_ignore_all_dups hist_ignore_space nobeep if [[ $_set_prompt == "p9k" ]]; then source ${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme