-
-
Save hughdunne/1996347c207fde88e1c1 to your computer and use it in GitHub Desktop.
Utility for switching between Unix screens.
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/sh | |
# Utility for switching between Unix screens. Gives you a warning if you | |
# try to attach to a screen while already attached. | |
# Note that when you create a screen, you can give it a name with the -S option. | |
# Usage: | |
# scr -- Get a list of existing screens. | |
# scr foo -- Attach to a screen with name matching "foo" e.g. 23560.myfooscreen. | |
if [ "$#" -eq 0 ] ; then | |
# Get a list of existing screens. | |
screen -ls | |
else | |
# Are we already attached to a screen? | |
screen -ls | grep \(Attached\)$ | |
if [ $? -eq 0 ] ; then | |
echo "You are attached to a screen, please detach first by hitting Control-A d" | |
exit 3 | |
fi | |
# In the following line, the first $1 refers to the first argument of this script, | |
# the second $1 is an Awk argument referring to the first field in the matching line. | |
screen -r $(screen -ls | awk "/$1/{print \$1}") | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment