Laid my hands on cmus recently and it got my spot
just right, lightweight yet powerful, and useful plugins with specialized
One thing is, if I use Krunner to start it, cmus will just silently lie backstage
listening on its socket and leave me no way to attach it to a GUI. This causes
big problems to me since I always set it to start automatically upon system
boot. Also, sometimes I may want to bring up cmus in GUI to alternate the
playlist/queue and send it backstage afterwards. With the default cmus-remote
it's pretty hard to achieve what I want, especially when I want to do most of the
work with shortcuts.
Messing around google and I found this solution which tries to attach/detach
cmus to a screen/tmux session, and it works
nicely. Also I add some keybindings to make the whole use case much smoother.
if ! screen -r -D cmus >/dev/null ; then
screen -S cmus /usr/bin/cmus "$@"
if ! tmux has-session -t cmus 2>/dev/null; then
tmux new-session -s cmus -d -n cmus -d "/usr/bin/cmus $@"
tmux attach -d -t cmus
Set it in the keybindings view (7) of cmus.
:bind -f common q shell screen -d cmus
:bind -f common q shell tmux detach-client -s cmus
I have a large collection of music and keep updating it all the time. Occassionally some jewel
will pop up in my radom list, and needs to be marked as my favorites immediately,
and I don't want to stop what I'm doing at that moment. The following script does the job for
me, and by assigning it to a shortcut, I can mark the current playing song as
my favorite and store it in a predefined playlist, without interrupting the
work at hand. The script is a modification of Markus00000's work here.
The original script rates the song at a scale of 1 to 5, feel free to grab it
if that's what you need.
# By Lynxiayel
# Based on the script by Markus00000 at:
# This script mark current playing song as your favorite and adds it to a m3u
# playlist which holds all your favorites.
# Path to playlists
# Prefix and suffix strings for the playlist file name
# Get current song from cmus
song=$(cmus-remote -Q | grep file)
# Error cases
if [[ -z "$song" ]]; then
echo 'No song is playing.'
# Path to lock file
# Lock the file (other atomic alternatives would be "ln" or "mkdir")
if ! flock -n 9; then
notify-send -t 5000 "Rating failed: Another instance is running."
# Strip "file " from the output
# Temporary file for grepping and sorting
# # Remove the song from the fav playlists
# if [[ -f "$f" ]]; then
# grep -vF "$song" "$f" > "$tmp"
# mv -f "$tmp" "$f"
# Append the song to the fav playlist
mkdir -p "$playlists"
echo "$song" >> "$f"
sort -u "$f" -o "$tmp"
mv -f "$tmp" "$f"
notify-send -t 3000 "$song added to the $pl_prefix list."
# The lock file will be unlocked when the script ends
Assume you have saved the aforementioned attach code in a script called cmus,
and put it in your system path, so it's found before the real cmus program. You
can do this by put the following command into your ~/.bashrc
Open the KDE custom shortcuts, either with krunner or in your app drawers, and
create a new shortcut group for cmus. Then create the following keys with your
choices of keybindings.
konsole -e "path/to/your/cmus/attach/script"
cmus-remote -v +5%
cmus-remote -v -5%
1 Aug 2017
1 Aug 2017