Last active
August 29, 2015 14:27
-
-
Save criztovyl/8804dd650e723914349b to your computer and use it in GitHub Desktop.
Opens remote cmus screen in current shell. Starts cmus if it's not running.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pimus() | |
{ | |
# Try to show cmus screen, start new cmus instance into cmus screen if not available | |
if ! screen -qr cmus; then | |
# Start new cmus into cmus screen | |
screen -mdS cmus cmus | |
# Wait for cmus socket (up to 5x5 seconds) | |
for (( i=0; i < 5; i++ )); do | |
# Do not wait if socket does exist already | |
[ -f .cmus/socket ] && break | |
# Wait for a file created in .cmus folder with 5 seconds timeout and store inotifywait output for later use. | |
event=`inotifywait -qt 5 -e create .cmus` | |
# Receive status | |
status=$? | |
# Act on status zero or one, ignore status two wich appears if inotifywait timed out | |
case $status in | |
0) | |
# All okay, if the socket file was created, break loop | |
[ "`echo $event | cut -d " " -f 3-`" == "socket" ] && break | |
;; | |
1) | |
# Exit if there was an error | |
exit | |
;; | |
esac | |
# Loop end | |
done | |
# Start playing | |
cmus-remote -p | |
# Show screen | |
screen -r cmus | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment