Somebody asked me for "something like dmenu" to control MPD with. I decided that would be a perfect job for the actual dmenu, and whipped up a little script to control MPD with dmenu
First it let's you pick an artist, and after selecting one, another instance of dmenu opens wich let's you pick an album to play, or decide to play all by that artist (given your music is stored like /musicdir/artist/album).
There's tons of different scripts around that pair MPD with dmenu, and even a few that do the artist/album two-level navigation. But everything I've seen was an awful heap of awking/seding, some even using temporary files. There's no need for all that. Yes, this script does need mpc installed, but honestly - I haven't seen somebody using MPD which didn't have it installed.
Also, this is the first dmenu/MPD script I've seen so far that exits gracefully when you hit ESC without selecting anything. All the other scripts seemed to add the entire library to the playlist in that case. All it needed was a simple check if the $ARTIST/$ALBUM variable is empty before calling mpc.
1 #!/bin/bash 2 3 if [[ -f $HOME/.config/dmenurc ]]; then 4 . $HOME/.config/dmenurc 5 else 6 DMENU="dmenu -i" 7 fi 8 9 ARTIST=$( mpc ls | $DMENU ) 10 11 if [[ $ARTIST == "" ]]; then 12 exit 1 13 else 14 ALBUM=$( echo -e "Play All\n$( mpc ls "$ARTIST" )" | $DMENU ) 15 16 if [[ $ALBUM == "" ]]; then 17 exit 1 18 else 19 mpc clear 20 if [[ $ALBUM == "Play All" ]]; then 21 mpc add "$ARTIST" 22 else 23 mpc add "$ALBUM" 24 fi 25 mpc play 26 fi 27 fi 28 29 exit 0