ArchLabs Linux

Another cmus script

Hi all, I come with an other cmus status script witch also brings “position & duration”, but I need your help to provide these feathures different colors …

#!/bin/bash
stat=$(cmus-remote -Q 2> /dev/null | grep status | cut -d ' ' -f2-)
duration=$(cmus-remote -Q 2> /dev/null | grep duration | cut -d ' ' -f2-)
current=$(cmus-remote -Q 2> /dev/null | grep position | cut -d ' ' -f2-)
artist=$(cmus-remote -Q 2> /dev/null | grep ' artist ' | cut -d ' ' -f3-)
song=$(cmus-remote -Q 2> /dev/null | grep title | cut -d ' ' -f3-)
if [[ "$stat" != "" && "$artist" != "" && "$stat" != "paused" ]]; then
  echo "$artist - $song $current / $duration"
  echo "$song"
  if [[ "$stat" == "playing" ]]; then
    echo "#7BA8CC"
  else
    echo "#1D2E38"
  fi
fi

I’m not sure how blocks expect colors but you can use

echo -e '\e[34mHello\e[0m'

To echo Hello in blue text (blue only if your terminal colours follow the standard scheme)

1 Like

24-bit (“true colour”) escape sequences are possible with a supported terminal emulator:

And for those variables try awk instead of grep & cut, for example:

stat=$(cmus-remote -Q 2> /dev/null | awk '/status/{print $2}')

etc

1 Like

Well indeed my question was about the display in the bar, for now it looks like this:

Van Halen - Women and children first 35/365

Where 35/365 is position/duration expressed in seconds, so I’d like to colorize this or put a “-” between the title and those guys, other than that my colors render just fine. Thanks again for the syntax.

What he’s doing with cut isn’t just printing a field, you need to do a lot more than that to emulate cut -d ' ' -f2-

1 Like

I found the solution, so simple:

if [[ "$stat" != "" && "$artist" != "" && "$stat" != "paused" ]]; then
  echo "$artist - $song - $current / $duration"
  echo "$song"

I just put an hyphen in front of $current. So now I have
Van Halen - Women and children first - 35/365 :innocent: