#!/bin/sh
nowPlaying=$(cmus-remote -Q 2>/dev/null)
title=$(echo "$nowPlaying" | grep 'tag title' | cut -d' ' -f3-)
artist=$(echo "$nowPlaying" | grep 'tag artist' | cut -d' ' -f3-)
repeat=$(echo "$nowPlaying" | grep 'set repeat ' | cut -d' ' -f3-)
shuffle=$(echo "$nowPlaying" | grep 'set shuffle' | cut -d' ' -f3-)
duration=$(echo "$nowPlaying" | grep 'duration' | cut -d' ' -f2-)
position=$(echo "$nowPlaying" | grep 'position' | cut -d' ' -f2-)
curStatus=$(echo "$nowPlaying" | head -1 | cut -d' ' -f2)
if [ "$curStatus" != "playing" ] && [ "$curStatus" != "paused" ]; then
printf "Nothing Playing"
exit 0
fi
((durationMinutes=$duration/60))
((durationSeconds=$duration%60))
((positionMinutes=$position/60))
((positionSeconds=$position%60))
if [ "$shuffle" = "true" ]; then
icons=" "
fi
if [ "$repeat" = "true" ]; then
icons="$icons "
fi
printf "\"%s\" by %s — %02d:%02d/%02d:%02d%s" "$title" "$artist" \
"$positionMinutes" "$positionSeconds" "$durationMinutes" \
"$durationSeconds" "$icons"