#!/bin/sh

cmus-remote -Q 2>&1| gawk '
/cmus is not running/ {quit=1}
/status/     {info["status"] =$2}
/^tag album/	     {info["album"]  = gensub("[^ ]+ album ", "", "")}
/^tag title/	     {info["title"]  = gensub("[^ ]+ title ", "", "")}
/^tag artist/     {info["artist"]  = gensub("[^ ]+ artist ", "", "")}
/^duration/   {info["d"] = $2;}
/^position/   {info["p"] = $2;}
END {
if (!quit)
{
    info["bar"] = (info["d"] > 0 ? info["p"]/info["d"]*100 : 0)
    printf "${alignr} %02d:%02d/%02d:%02d\n", info["p"]/60, info["p"]%60, info["d"]/60, info["d"]%60
    printf "${execbar echo %d}\n", info["bar"]
    printf "${color yellow}Vol     :${alignr}${color}${mixer}\n"
    printf "${color yellow}Artist  :${alignr}${color}%.20s\n", info["artist"]
    printf "${color yellow}Title   :${alignr}${color}%.20s\n", info["title"]
    printf "${color yellow}Album   :${alignr}${color}%.20s\n", info["album"]
}
}'
