fix: unicode character display

unicode characters are treated as they were several characters : cutting
a string at char 15 *might* cut in the middle of a unicode character

-> unicode() to convert a unicode char to its ASCII equivalent
[ will be updated each time we come across an error, though it should
not appear beside apostrophes ]
This commit is contained in:
David JULIEN 2021-03-11 01:53:04 +01:00
parent e224b95986
commit 8ddcf5b6c2
1 changed files with 3 additions and 2 deletions

View File

@ -10,12 +10,13 @@
######################################################################
unicode() { sed "s/[]/'/g;s/[“”]/\"/g"; }
format() { sed "s/^volume:n\/a.*//g;/^volume:/d;s/\\&/&/g;s/\\[paused\\].*//g;s/\\[playing\\].*//g"; }
mpc="$(mpc --format "%albumartist% - %title%")"
title="$(echo "$mpc" | head -n1 | awk -F " - " '{ printf "%s", $2 }')"
title="$(echo "$mpc" | head -n1 | cut -d'-' -f2 | unicode)"
[ "$(echo "$title" | wc -c)" -gt 18 ] && title="$(printf "%.15s..." "$title")"
artist="$(echo "$mpc" | head -n1 | awk -F " - " '{ printf "%s", $1 }')"
artist="$(echo "$mpc" | head -n1 | cut -d'-' -f1 | unicode)"
[ "$(echo "$artist" | wc -c)" -gt 18 ] && artist="$(printf "%.15s..." "$artist")"
status="$(echo "$mpc" | tail -n2 | format)"