Skip to content

Instantly share code, notes, and snippets.

@IcyMidnight
Created March 1, 2012 21:24
Show Gist options
  • Save IcyMidnight/1953340 to your computer and use it in GitHub Desktop.
Save IcyMidnight/1953340 to your computer and use it in GitHub Desktop.
Manage you screen sessions
#!/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