#!/bin/sh
dir=/data/mpd/music

add_pl () {
    mpc clear
    cat "$1" | mpc add
    mpc play
}

add_dir () {
    mpc clear
    mpc add "$1"
    mpc play
}

test $# -ne 1 && echo "$0 takes 1 argument" && exit 1

target="`sed -n -e "s%^$1[[:space:]]\(.*\)[[:space:]]*$%\1%p" /data/mpd/playlists/index`"
[ -e "$dir/$target" ] || exit 1
[ -f "$dir/$target" ] && add_pl  "$target" && exit
[ -d "$dir/$target" ] && add_dir "$target" && exit

