I Don't Know How I Lived Without Screen

''This is not my talk yet, just fleshing it out. Work in progress. Move along, move along... chruck 15:26, 4 September 2009 (UTC)''

discuss Contents, "Here's what I use"

= Concepts =

What Screen Is

 * Face it: Linux:  must use commandline
 * "Window Manager"
 * Allows reconnecting to sessions
 * Not invasive: Gets out of the way
 * Multiple windows on the same virtual terminal
 * Multiple access to the same virtual terminal

Nominclature

 * terminal : display that shows standard output from computer, usually text -F1
 * virtual terminal (vt) : terminal that may/not be attached to display -Fx
 * X terminal (xterm) : X window program that displays vt, eg xterm, Kterm, Gnome-terminal, rxvt, Eterm
 * attach : session in current terminal
 * detach : session running in background on vt
 * window : process (usually shell) running on its own vt
 * session : an instance of screen

Use Cases
discuss later?

Commandline Options

 * -ls -list : list screen sockets
 * -d [label] : detach
 * -r [label] : reattach
 * -DR [label] : detach/reattach force (create if not existing)
 * -x : multipass [label]
 * -wipe : clean up socket list
 * -S [label] : label screen session

= Concretes =

Key Bindings for Commands
screen
 * -A &rarr; screen's command prefix. All the following need -A prepended:
 * ? : help
 * d : detach
 * c : create a window echo zeroth, echo first, second, third
 * , n : next window, wraps around
 * p : prev window, wraps around
 * -A : last window
 * 0 to 9 : jump to that window number first &rarr; third
 * a : send -A to vt vim
 * A : window title
 * w : show windows
 * " : goto window from list
 * S : split
 *  : focus
 *  : begin copy mode (view scrollback)
 * ] : paste

Copy Mode

 * vi-like movement, searching
 *  marks what to copy
 *  exits

.screenrc
defscrollback 10000 bindkey -d "\000" stuff "\010" caption always screen su - screen mutt screen less +F /var/log/messages screen
 * 1) Have 1000 lines buffered to go back to via C-a esc  (-h)
 * 1) On the OLPC, the 'erase' key becomes 'NUL'.  This fixes:

= Conclusions =

Gotchas

 * $DISPLAY
 * $TERM
 * screen within screen
 * other programs that use -A (minicom, vim)
 *  &rarr; vbell
 * multi-display on different-sized vt

Resources

 * -A ?
 * man screen
 * info screen
 * google
 * uclug
 * Eric

Newbie Questions
Your turn to ask

Auto-reconnection script
The following script attempts to reconnect you to the last screen session that your remote IP started via SSH. If multiple exist, it reconnects you to the first available session. If none are available, it creates a new session. Just stick this in your ~/.bashrc file:

if [ -n "$SSH_CONNECTION" ] && [ -z "$SCREEN_EXIST" ] && [ -z "$BASH_EXECUTION_STRING" ]; then export SCREEN_EXIST=1 client_id=`echo $SSH_CLIENT | awk '{ print $1 }'` count=`screen -ls | grep "$client_id" | grep '(Detached)' | wc -l` # Check to see if there's an existing session from this IP    if [ $count -gt 0 ]; then session_id=`screen -ls | grep "$client_id" | grep '(Detached)' | head -1 | awk -F'.' '{ print $1 }'` screen -DR $session_id else screen -R $client_id fi    # Uncomment this line if you want your SSH session to disconnect when you exit the screen session # However, if this script has bugs...you may just lock yourself out of your machine, short of a live CD... #exit fi