# screen* is necessary as `screen` uses screen.linux for example for a linux
# console which would otherwise cause an infinite loop.
if [[ $TERM != screen* && $TERM != 'dumb' ]]; then
+ # Get running detached sessions.
+ session=$(screen -list | grep 'Detached' | awk '{ print $1; exit }')
# Create a new session if none is running.
- if [[ $(screen -list | grep "Detached" | wc -l) == 0 ]]; then
+ if [[ -z $session ]]; then
screen
# Reattach to a running session.
else
- screen -r
+ screen -r $session
fi
fi