#!/bin/sh

dmenu_args=${@:--c -l 15 --bw 1 -n ebdbb2 -N 282828 -s 282828 -S 689d6a}
dmenu="wmenu $dmenu_args"

add_menu()
{
	toadd=$( (printf '%s\n' "*"; mpc ls "$1") | $dmenu)
	if [ "$toadd" = "" ]; then
		return
	fi
	if [ "$toadd" = "*" ]; then
		mpc -q add "$1"
		return
	fi

	add_menu "$toadd"
}


list_songs()
{
	mpc playlist | nl -w8 -s " "
}

menu=$(printf "%s" "$menuitems"; list_songs)
currently_playing=$(mpc status | grep playing | sed 's/.*#\([0-9]*\).*/\1/')
if [ -n "$currently_playing" ]; then
	currently_playing_pos=$((currently_playing+menuitems_num))
	echo $currently_playing_pos
	menu=$(printf "%s" "$menu" | sed "$currently_playing_pos"'s/^ />/')
fi
choice=$(printf "%s" "$menu" | $dmenu)

case "$choice" in
"")
	mpc -q "${choice#: }"
	;;
*)
	mpc -q play "$(printf "%s" "$choice" | sed 's/>\?\ *\([0-9]*\).*/\1/')"
	;;
esac
