detachable cmus - cmus/cmus GitHub Wiki
Cmus doesn't support detaching natively. However, using screen and a shell alias, you can have very similar behavior. Add the following line to a startup file of your shell, e.g. to $HOME/.profile
alias cmus='screen -q -r -D cmus || screen -S cmus $(which --skip-alias cmus)'
An alternative that uses tmux:
alias cmus='tmux new-session -A -D -s cmus "$(which --skip-alias cmus)"'
Additionally, if you want to have cmus with tmux in more than one terminal you can use the following alias:
alias cmus='tmux attach-session -t cmus || tmux new-session -A -D -s cmus "$(which --skip-alias cmus)"'
If you're an existing tmux user, you should use the following alias:
alias cmus='tmux new-session -s cmus -d "$(which --skip-alias cmus)" 2> /dev/null; tmux switch-client -t cmus'
Then reload the startup file either by restarting your shell, or by typing in:
$ source $HOME/.profile
Now in cmus, set the q key to screen detach:
:bind -f common q shell screen -d cmus
Tmux alternative:
:bind -f common q shell tmux detach-client -s cmus
And for existing tmux users:
:bind -f common q shell tmux switch-client -l
Finished! This way, if you press q cmus will simply go in the background (really fast), and by typing cmus in the shell you just resume where you left of. If you want to really quit cmus, you can simply enter
:quit
Systemd unit, change "chip" by your username:
[Unit]
Description=cmus
[Service]
Type=forking
User=chip
ExecStart=/usr/bin/screen -d -m -S cmus /usr/bin/cmus --listen /run/user/1000/cmus-socket
Environment="HOME=/home/chip" "USERNAME=chip"
[Install]
WantedBy=multi-user.target