Created
March 1, 2012 21:24
-
-
Save IcyMidnight/1953340 to your computer and use it in GitHub Desktop.
Manage you screen sessions
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 | |
if [ -z "$1" ]; then | |
options=0 | |
while read line; do | |
if [[ $line =~ ([0-9]+)\.([a-zA-Z0-9_]+) ]]; then | |
let "options = options + 1" | |
echo -n "(${options}) " | |
echo -n " - ${BASH_REMATCH[2]} - " | |
sessions[$options]="${BASH_REMATCH[2]}" | |
fi | |
echo $line | |
done <<< "`screen -list`" | |
echo "Select a screen. Type 'n' to get a new screen" | |
echo "Put an d after to detach any other connections" | |
read option attach_option | |
if [ "$option" == "n" ]; then | |
attach_option="n" | |
echo -n "Enter screen name: " | |
read screen_name | |
else | |
screen_name=${sessions[option]} | |
fi | |
else | |
screen_name=$1 | |
attach_option="d" | |
fi | |
if [ -n "$screen_name" ]; then | |
if [ "$attach_option" == "d" ] || [ "$attach_option" == "n" ]; then | |
screen -RaAD -S $screen_name | |
else | |
screen -x -S $screen_name | |
fi | |
else | |
echo "No screen name entered" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment