# Using Screen

I prefer tmux. Unfortunately, screen is the only terminal multiplexer available on CHPC. So in order to get acquainted, I'm writing myself this article.

Multiplexers are awesome! They let you manage several terminal "tabs" from within a single "physical" terminal. You can rename the tab, to remind you of its purpose. This lets you organize your workspace. A more important feature, is that it lets you detach from a working session and reattach later. This is useful if you accidentally lose connectivity, like when working from a coffee-shop, or your VPN kicks you off. You can just reattach and continue from where you left off. No need to setup your complex working environment all over again. You can also have a session of remote paired programming in which you and someone else connect to the same session and take turns typing commands. And finally, it gives you the ability to have long running processes.

# Useful Keyboard shortcuts

All shortcuts require the prefix key ctrl+a followed by the Additional Key.

Additional Key Command
c Create a new window
A Rename the current window
" List all windows
n Next window
p Previous window
1-9 Switch to window 1..9, respectively
S Split the window into two horizontal regions
Tab Switch focus to the next split
Q Close all splits but the current one
X Close the current split
ctrl+a Quick switch to previous window
d Detach from session
k Kill current window
\ Quit the entire session (kill all windows)

# Move a window order

To move the current window to position n just type prefix key + :number n

# Reatttach to a previous session:

screen -r         # if only session
screen -r 6       # if only session that starts with 6
screen -r 622219  # full name

# Starting a New Named Session

screen -S session_name

# Check current sessions:

screen -ls

# One-time Setup of the config file

These are some useful customizations to make to the default configuration file ~/.screenrc:

# Start window count at 1
bind c screen 1
bind ^c screen 1
bind 0 select 10
screen 1

# Add color
term screen-256color

# Add statusbar
hardstatus off
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][ %{y}Load: %l %{g}][%{B} %m-%d %{W} %c %{g}]'

# Welcome message off
startup_message off