From 8ddcf5b6c28fd72db5488954840d874bb1e3e536 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Thu, 11 Mar 2021 01:53:04 +0100 Subject: [PATCH] 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 ] --- .local/bin/statusbar/sb-music | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.local/bin/statusbar/sb-music b/.local/bin/statusbar/sb-music index 3f1aec9..7b5d802 100755 --- a/.local/bin/statusbar/sb-music +++ b/.local/bin/statusbar/sb-music @@ -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)"