#!/bin/bash if [ "`pgrep -x cmus`" == "" ]; then echo "" exit 0 fi data="$(cmus-remote -Q)" status=$(echo "$data" | awk '/status / {print $2}') artist=$(echo "$data" | awk '/tag artist / {$1="";$2="";print substr($0,3)}') title=$(echo "$data" | awk '/tag title / {$1="";$2="";print substr($0,3)}') duration=$(echo "$data" | awk '/duration/ {print $2}') position=$(echo "$data" | awk '/position/ {print $2}') nowplaying="$artist - $title" position_formatted="" duration_formatted="" if [ "$position" != "" ]; then if [ $position -ge 3600 ]; then position_formatted+=$(printf '%02d:' $(($position/3600))) fi position_formatted+=$(printf '%02d:%02d' $(($position%3600/60)) $(($position%60))) fi if [ "$duration" != "" ]; then if [ $duration -ge 3600 ]; then duration_formatted+=$(printf '%02d:' $(($duration/3600))) fi duration_formatted+=$(printf '%02d:%02d' $(($duration%3600/60)) $(($duration%60))) fi nowplaying+=" [$position_formatted/$duration_formatted]" if [ "$status" == "paused" ]; then nowplaying+=" [paused]" elif [ "$status" == "stopped" ]; then nowplaying+=" [stopped]" fi echo "$nowplaying"