I initially turned to CMUS because every other music player struggled with my external hard drive. However, I stayed for its efficient and robust command-line interface. One feature I found myself missing, a nostalgic memory from my Rockbox days, was the ability to shuffle music by entire albums rather than individual tracks. Today, I’m excited to share a Bash script that fills this gap. It organizes your songs into albums, shuffles those albums, and seamlessly integrates this new playlist back into CMUS.
The Problem: Cmus and Playlists
Cmus is a feature-rich music player that runs in the terminal, offering a fast and resource-efficient way to play your favorite tunes. While it does have a shuffle feature, it shuffles individual songs rather than complete albums. For those of us who appreciate the cohesiveness of listening to an entire album, this can be a bit of a letdown.
The Solution: A Bash Script to Shuffle Albums
To solve this problem, I’ve written a Bash script that automates the process of creating a shuffled playlist of complete albums. The script uses
awk to group songs by their albums and
awk for loops to shuffle these groups. Finally, it imports this new playlist into Cmus.
The script also allows you to set an album limit (currently manual by setting the ALBUM_LIMIT variable), so you can control how many albums appear in your shuffled playlist.
How It Works
Fetching the Latest Library: The script starts by fetching the latest library from Cmus using
Grouping Songs by Album: It then uses
awkto read through this library and group songs by their album.
awkscripts are used to shuffle these grouped albums.
Importing the Playlist: Finally, the script imports this new shuffled playlist back into Cmus.
- Download the script and place it in a directory.
- Make the script executable with
chmod +x script-name.sh.
- Run the script with
Why This Script is just the beginning
This script not only enhances your Cmus experience but also demonstrates the power of shell scripting for automating cmus-related tasks. Using the handy
cmus-remote tool, nearly any feature that you’d like to have from Rockbox or any other system is one script away.
This Bash script offers a simple yet effective way to shuffle complete albums in Cmus, providing a more Rockbox-like listening experience. It’s a great example of how we can use scripting to extend the functionality of existing software to better meet our needs.
So go ahead, give it a try and let your favorite albums play in a new, shuffled order!