#!/bin/sh

case $BUTTON in
		1)notify-send "$(cmus-remote -Q | grep position | awk '{ printf "%02i:%02i", $2/60, $2%60}')/$(cmus-remote -Q | grep duration | awk '{ printf "%02i:%02i\n", $2/60, $2%60} ') ($(cmus-remote -Q | grep status | cut -d ' ' -f 2-))
Artist: $(cmus-remote -Q | grep "tag artist " | cut -d ' ' -f 3-)
Album: $(cmus-remote -Q | grep "tag album " | cut -d ' ' -f 3-)
Track: $(cmus-remote -Q | grep "tag title " | cut -d ' ' -f 3-)
Genre: $(cmus-remote -Q | grep "tag genre " | cut -d ' ' -f 3-)
Mode:  $(cmus-remote -Q | grep "aaa_mode"   | cut -d ' ' -f 3)
Format: $(cmus-remote -Q | grep file | rev | cut -d '.' -f 1 | rev)
Shuffle: $(cmus-remote -Q | grep "set shuffle " | cut -d ' ' -f 3-)
Repeat: $(cmus-remote -Q | grep "set repeat_current " | cut -d ' ' -f 3-)";;
	
		3)urxvt -e vim ~/.local/bin/statusbar/cmus;;
		4)cmus-remote --next;;
		5)cmus-remote --prev;;
esac

pgrep -x cmus >/dev/null || exit 0

status="$(cmus-remote -Q | grep status | cut -d ' ' -f 2)"
artist="$(cmus-remote -Q | grep "tag artist" | cut -d ' ' -f 3- | tr -d "\n")"
track="$(cmus-remote -Q | grep "tag title" | cut -d ' ' -f 3- | tr -d "\n")"
echo -n "$artist - $track"
[ "$status" = "playing" ] || echo -n " [P]"