From 40aa1b85c71a934fd3e39eea01e76fcb3277a779 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 15 Apr 2020 14:13:26 +0200 Subject: [PATCH] Remove 2b2t queue, silent errors of covid prompt and use busctl for better mpris output parsing --- custom/segments.zsh | 21 +++++---------------- preferences.zsh | 1 - 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/custom/segments.zsh b/custom/segments.zsh index 469633c..04c5028 100644 --- a/custom/segments.zsh +++ b/custom/segments.zsh @@ -1,5 +1,4 @@ typeset -gi _mail_change_time -typeset -gi _mclog_change_time typeset -gi _pacman_check_time typeset -gi _mail_count typeset -gi _upgrade_packages @@ -9,11 +8,11 @@ function prompt_docker_host() { typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker' function prompt_dbus_mpris() { typeset -g _mpris_LASTRESP="${_mpris_RESP:-0}" - typeset -g _mpris_RESP="$(qdbus org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata 2>/dev/null)" + typeset -g _mpris_RESP="$(busctl --user --json=short get-property org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Metadata 2>/dev/null | jq '.data')" if [[ $_mpris_RESP != $_mpris_LASTRESP ]]; then - typeset -g _mpris_RFMT="$(print ${_mpris_RESP} | grep -oP '(?<=^xesam:title: ).+')" - local ARTIST="$(print ${_mpris_RESP} | grep -oP '(?<=^xesam:artist: ).+')" - [ ! -z ${ARTIST} ] && _mpris_RFMT="${ARTIST} - ${_mpris_RFMT}" + typeset -g _mpris_RFMT="$(print ${_mpris_RESP} | jq --raw-output '."xesam:title".data // ""')" + local ARTIST="$(print ${_mpris_RESP} | jq --raw-output '."xesam:artist".data[0] // ""')" + [ ! -z ${ARTIST} ] && _mpris_RFMT="${ARTIST} - ${_mpris_RFMT%% \(*\)}" fi p10k segment -b purple -i '' -t "${_mpris_RFMT}" -c "${_mpris_RFMT}" } @@ -36,22 +35,12 @@ function prompt_pacman_upgrade() { p10k segment -b cyan -i '' -t "${_upgrade_packages}" } typeset -g POWERLEVEL9K_PACMAN_UPGRADE_SHOW_ON_COMMAND='pacman' -function prompt_2b2t_queue() { - local FILE=~/.local/share/multimc/instances/Impact\ 4.8.3\ -\ 1.12.2\ -\ Forge/.minecraft/logs/latest.log - local -a stats - zstat -A stats +mtime -- $FILE 2>/dev/null || return - if [[ $stats[1] != $_mclog_change_time ]]; then - local _last_LOG=($(tail -n1 $FILE)) - _mclog_change_time=$stats[1] - fi - [ ${_last_LOG[-2]:-0} = 'queue:' ] && p10k segment -b green -i '' -t "${_last_LOG[-1]}" -} function prompt_covid_19() { local tmpfile=/tmp/covidres local -a stats zstat -A stats +mtime -- $tmpfile 2>/dev/null if [[ $stats[1] < $(($epochtime[1]-86400)) ]]; then - local result=$(curl -sS https://api.covid19api.com/country/germany/status/confirmed/live | jq -e '.[-1].Cases') + local result=$(curl -sL https://api.covid19api.com/country/germany/status/confirmed/live | jq -e '.[-1].Cases') [ ! -z $result ] && print $result > $tmpfile fi p10k segment -b red -i '' -t "$(< $tmpfile)" diff --git a/preferences.zsh b/preferences.zsh index 9bbfa39..6907e1e 100644 --- a/preferences.zsh +++ b/preferences.zsh @@ -30,7 +30,6 @@ if [ -z "$SSH_CONNECTION" ] && ! [ -z "$DISPLAY" ]; then vim_shell new_mail covid_19 - 2b2t_queue dbus_mpris public_ip newline