Turns out that pipe buffering was causing problems with mpg123's
-C option. This can be solved by using the
--line-buffered option in grep, or
-u in sed.
In the end, the set of flags I ended up using was:
mpg123 -Z -C --title */* 2>&1 | grep --line-buffered -Ev "High Performance|written and copyright by|without any warranty but with best wishes|Terminal control enabled|MPEG 1.0|Decoding of" | sed -uE 's/Playing MPEG stream [0-9]+ of [0-9]+: //' | sed -uE "s/Directory: //" | sed -uE "s/\.\.\.//" | sed -uE '/^\s*$/d'
I'm going through the options step by step. Some of them answer the broader question of having a convenient mpg123 setup.
-Z is eternal random shuffle
-C allows for control commands
--title changes the terminal's title to the title of the current song
*/* looks for files in current subdirectories. If the files are in a given directory, '*' would suffice.
2>&1 redirects from standard error (to which mpg123 prints) to standard output, which can be manipulated using pipes
--line-buffered in grep and the
-u flag on sed avoid buffering, which was what was causing me problems.
- Other flags are just regex toggles and non-central to the question.
I then aliased this command for ease of use.
alias pmr="clear; mpg123 -Z -C --title */* 2>&1 | grep --line-buffered -Ev 'High Performance|written and copyright by|without any warranty but with best wishes|Terminal control enabled|MPEG 1.0|Decoding of' | sed -uE 's/Playing MPEG stream [0-9]+ of [0-9]+: //' | sed -uE 's/Directory: //' | sed -uE 's/\.\.\.//' | sed -uE '/^\s*$/d'" ## pmr := play music recursively
-f as a flag to avoid buffering, but it kept giving me problems.