#!/bin/sh

# Author: Petter J. Barhaugen (petter@petternett.no)
# Requires FontAwesome or an emoji font to be installed.

# Add to Polybar:
#
# [module/cmus-statusbar]
# type = custom/script
# exec = ~/path/to/cmus-statusbar
# exec-if = pgrep -x cmus
# interval = 1
# label = %output:0:32:…%
# click-left = cmus-remote -u
# tail = true

# Adding to i3blocks:
#
# [music]
# command = ~/path/to/cmus-statusbar
# interval = 1

# To run independently of Polybar (like in i3blocks), uncomment the following line:
#pgrep cmus>& /dev/null
[ $? -eq 0 ] && [ $(cmus-remote -Q | grep status | cut -d ' ' -f 2) != "stopped" ] &&
  artist=$(cmus-remote -Q | grep 'tag artist' | cut -d ' ' -f 3-) &&
  title=$(cmus-remote -Q | grep 'tag title' | cut -d ' ' -f 3-) &&
  icon=$([ $(cmus-remote -Q | grep 'status' | cut -d ' ' -f 2) == "paused" ] &&
    echo "" || echo "") &&
  echo $icon $artist - $title 2>&1

exit 0
