Skip to content

Instantly share code, notes, and snippets.

@ryanlane
Created May 23, 2023 17:27
Show Gist options
  • Save ryanlane/42dca0141f2a6665dfcb76ed0612dbff to your computer and use it in GitHub Desktop.
Save ryanlane/42dca0141f2a6665dfcb76ed0612dbff to your computer and use it in GitHub Desktop.
#!/bin/bash
# List running screen sessions and extract session names
screen_list=$(screen -ls | awk '/[0-9]+\.[a-zA-Z0-9_-]+\t/ { print $1 }')
# Check if any sessions are running
if [[ -z $screen_list ]]; then
echo "No screen sessions are currently running."
exit 1
fi
# Display a menu to select a session
echo "Select a screen session to connect:"
PS3="Enter your choice: "
select session in $screen_list; do
if [[ -n $session ]]; then
screen -x "$session" # Connect to the selected session
break
else
echo "Invalid choice. Please try again."
fi
done
@ryanlane
Copy link
Author

If you have a lot of screen sessions and don't want to type anything to connect to them then use this handy script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment