Screen RC GNU Screen

, par MiKaël Navarro

"GNU Screen, un logiciel libre, est un multiplexeur de terminaux en mode texte. Screen est développé par le Projet GNU. Il permet à un utilisateur d’accéder de multiples sessions de terminal à l’intérieur d’une simple fenêtre de terminal, ou d’une session distante typiquement lancée par SSH. Il s’avère donc très pratique pour gérer de multiples processus." Wikipedia.

Pour une doc / usage cf. GNU Screen

Configuration de la session Screen

On commence par définir le shell utilisé ainsi que le type de terminal :

# Terminal confs
shell bash  # zsh is too long
term xterm

Paramétrage de l’écran de demarrage, du bip, ...

# Select whether you want to see the copyright notice during startup
startup_message off

# Visual bell
vbell on
# Instead of "Wuff ---- Wuff!!", which is pretty stupid
#vbell_msg "beep"

# Scrollback lines
defscrollback 1024

# When you are familiar with the game "nethack",  
# you  may enjoy the nethack-style messages which will
# often blur the facts a little, but are much funnier to read
nethack on

# The message specified here is output
# whenever a `power detach' was performed
pow_detach_msg "bye"

Ensuite on ouvre automatiquement des fenêtres, sur des dossiers, ou des machines distantes, ou encore sur le web :

# Startup windows
screen 0 env TERM=xterm lynx http://www.google.com/linux
screen 0
screen 1 ssh -X root@unit
chdir $HOME/dev
screen -t dev 2
chdir
screen 0

Des raccourcis claviers :

# Key bindings
bind 'w' screen -t 'lynx' env TERM=xterm lynx http://www.google.com/linux
bind 'v' screen -t 'vim' vi
bind 'l' windowlist -b
bindkey -k k1 select 1  # F1 = screen 1
bindkey -k k2 select 2  # F2 = screen 2
bindkey -k k3 select 3  # F3 = screen 3
bindkey -k k4 select 4  # F4 = screen 4
#bindkey -k F1 prev      # F11 = previous
#bindkey -k F2 next      # F12 = next

Enfin on définit des commandes appelées à intervals réguliers afin de mettre à jour la légende des fenêtres et la ligne de status :

# Backticks to display information in status bar
backtick 1 5 5 uptime
backtick 2 0 0 uname -a

# Activate caption (even if only one window)
# Displays a list of all the windows
# and their numbers on the left side,
# and the date and time on the right side:
caption always "%w%=%d/%m/%Y %c"

# Activate status line
hardstatus on
hardstatus alwayslastline
hardstatus string "%2`%=%1`"
# Current version and the compile date in the status line
version
.screenrc

Tips & tricks

Si les touches backspace ou delete ne fonctionnent pas sous Screen :

bindkey -d -k kb stuff ^H  # backspace
bindkey -d -k kD stuff ^?  # delete

Pour garder les connections SSH ouvertes :
Cf. Secure SHell