fI am reading a book on VimL (Vimscript) and it introduced me to mpc, a client for Music Player Daemon (MPD) . In this post I show you how  to set up mpc and how to quickly select and play music from the command line.

After getting the two with brew install mpc / mpd, you define where your music lives:

$ cat ~/.mpdconf
  bind_to_address  ""
  music_directory  "/Users/bbelderb/Music/"
  db_file  "/Users/bbelderb/Music/mpd.db"
  audio_output {
    name  "audio"
    type  "osx"

And you create the DB file:

$ touch ~/Music/mpd.db

Then you can start playing music with:

$ mpc update
$ mpc ls | mpc add 
$ mpc play

(use "listall" instead of "ls" if you have subdirectories in your defined music_directory)

Now I wondered how to quickly search for songs and play the search result.

I ended up adding this to my .bashrc:

alias mp="mpc toggle" # handy to quickly stop / resume music
alias mn="mpc next"
function ms() { mpc search any $1; }
function mss() { mpc clear 2>&1 >/dev/null && mpc search any $1|mpc add && mpc play; }

Note the difference between ms and mss: former just lists search results, the latter plays them as a new playlist. Thanks to this StackExchange thread.

So now if I want to play something specific I can do so pretty quickly (of course my options are limited to the music in the defined music_directory):

$ mpc stats
Artists:     66
Albums:       6
Songs:      120
# list search results
$ ms tony

# same, but play them  as well
$ mss tony
Tim Ferriss: Bestselling Author, Human Guinea Pig - Tony Robbins on Morning Routines, Peak Performance & Mastering Money - Part 1 of 2
 [playing] #1/2   0:00/68:20 (0%)

# create new playlist on-the-fly, searching for "roni" (of Roni Size) 
# result: a new playlist of 6 hits plays:
$ mss roni
 Roni Size - It's Jazzy (Nu:Tone Remix)
 [playing] #1/6   0:00/6:06 (0%)
Now back to the book on VimL / vimscripting ...

Bob Belderbos

Software Developer, Pythonista, Data Geek, Student of Life. About me