All pastes #907115 Raw Edit

Something

public text v1 · immutable
·published 2008-02-17 07:11 UTC
rendered paste body
#!/bin/bash                                                                                                                                                                                                      
                                                                                                                                                                                                                 
ACTIVE=$(screen -ls|grep -ci attached)                                                                                                                                                                           
AVAIL=$(screen -ls|grep -ci detached)                                                                                                                                                                            
                                                                                                                                                                                                                 
for dead in $(screen -ls | grep -i dead)                                                                                                                                                                         
do                                                                                                                                                                                                               
    # bring out your dead                                                                                                                                                                                        
    screen -wipe $dead                                                                                                                                                                                           
done                                                                                                                                                                                                             
                                                                                                                                                                                                                 
if [ $TERM != 'screen' ];then                                                                                                                                                                                    
    if [ $AVAIL -ge 1 ]; then                                                                                                                                                                                    
        if [ $AVAIL -eq 1 ]; then                                                                                                                                                                                
            screen -r; exit                                                                                                                                                                                      
        else                                                                                                                                                                                                     
            echo "Multiple screens available:"                                                                                                                                                                   
            screen -ls | grep -i detached                                                                                                                                                                        
            read -p "Select one (or nothing for new): " ATTACH                                                                                                                                                   
        fi                                                                                                                                                                                                       
    elif [ $ACTIVE -ge 1 ]; then                                                                                                                                                                                 
        read -p "All sessions attached, attach to one? (y/n): " YN                                                                                                                                               
        YN=$(echo $YN | tr y Y)                                                                                                                                                                                  
        if [ $YN == 'Y' ]; then                                                                                                                                                                                  
            screen -ls | grep -i attached                                                                                                                                                                        
            read -p "Select one (or nothing for new): " ATTACH                                                                                                                                                   
        else                                                                                                                                                                                                     
            screen; exit                                                                                                                                                                                         
        fi                                                                                                                                                                                                       
    fi                                                                                                                                                                                                           
    if [ -n "$ATTACH" ]; then                                                                                                                                                                                    
        screen -DR $ATTACH                                                                                                                                                                                       
    else                                                                                                                                                                                                         
        screen                                                                                                                                                                                                   
    fi                                                                                                                                                                                                           
fi