feat: prevent sb-music to print long strings

parse title and artist individually to prevent the final string to too
long (and cut)
This commit is contained in:
David JULIEN 2021-02-20 19:07:30 +01:00
parent 87e453c7a8
commit 972abb9bf7

View File

@ -10,10 +10,15 @@
###################################################################### ######################################################################
format() { sed "s/^volume:n\/a.*//g;/^volume:/d;s/\\&/&/g;s/\\[paused\\].*//g;s/\\[playing\\].*//g"; }
mpc="$(mpc --format "%albumartist% - %title%")" mpc="$(mpc --format "%albumartist% - %title%")"
format() { tac | sed "s/^volume:n\/a.*//g;/^volume:/d;s/\\&/&/g;s/\\[paused\\].*/⏸/g;s/\\[playing\\].*/🎵/g" | paste -sd ' ' -;} title="$(echo "$mpc" | head -n1 | awk -F " - " '{ printf "%s", $2 }')"
[ "$(echo "$title" | wc -c)" -gt 18 ] && title="$(printf "%.15s..." "$title")"
artist="$(echo "$mpc" | head -n1 | awk -F " - " '{ printf "%s", $1 }')"
[ "$(echo "$artist" | wc -c)" -gt 18 ] && artist="$(printf "%.15s..." "$artist")"
status="$(echo "$mpc" | tail -n2 | format)"
pgrep -f sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 & pgrep -f sb-mpdup >/dev/null 2>&1 || sb-mpdup >/dev/null 2>&1 &
mpc=$(echo "$mpc" | format) [ -n "$status" ] && printf " %s %s - %s " "$status" "$artist" "$title"
[ -n "$mpc" ] && printf " %s " "$mpc"