Skip to content

Instantly share code, notes, and snippets.

@mattkenefick
Last active May 16, 2016 14:34
Show Gist options
  • Save mattkenefick/e4e54137d0a70b056d58a22259495181 to your computer and use it in GitHub Desktop.
Save mattkenefick/e4e54137d0a70b056d58a22259495181 to your computer and use it in GitHub Desktop.
scrn
--------
Usage
--------
# Creates a background screen with a name `make-assets` that runs the command `gulp watch`
# Can be found by running `screen -list` and resuming.
# You can change this name to be whatever you want instead of `make-assets`
> scrn make-assets "gulp watch"
[scrn] Background screen (make-assets) gulp watch
> scrn run-node "node server.js"
[scrn] Background screen (run-node) gulp watch
# Example of created screens
> screen -list
There is a screen on:
19552.make-assets (Detached)
19659.run-node (Detached)
2 Sockets in /var/folders/cs/vnnyv0kj3ts4vdftv28fsj4m0000gn/T/.screen.
# Destroy screens with a particular name (make-assets)
> scrn make-assets X
-------
For your .bashrc / .bash_profile
-------
scrn() {
local cmd=''
local name=$1
local remove=''
if [ "$2" = "X" ] ; then
remove='true'
elif [ -n "$2" ] ; then
cmd=$2
fi
if [ -n "$cmd" ] ; then
echo "[scrn] Background screen ($name) $cmd"
screen -dmS $name sh
screen -S $name -p 0 -X stuff $"$cmd"
screen -S $name -p 0 -X stuff $'\n'
elif [ -n "$remove" ] ; then
echo "[scrn] Removing ($1)"
screen -ls | grep $name | cut -d. -f1 | awk '{print $1}' | xargs kill
screen -list
else
echo "[scrn] Starting ($name)"
screen -dmS $name sh
screen -r $name
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment