Screen by default?

Following up on Dustin's blog about our idea of proposing screen configurations for ubuntu server, here is how I have set up my environment to use screen by default on my machines.

First of all, I modified my .bashrc to add the following at the end:

if [ "$TERM" != "screen" ]; then
    #screen -D -R
    #Update 2008 Dec 16: -xRR is way better
    screen -xRR

Which, if my bash session is not opened from a screen, will try to find an existing screen session and reattach to it, otherwise create one. This also prevents opening screen within a screen when connecting to another host with a similar setup.

Update 2008 Dec 16: The -xRR option will not detach a current running screen.  It will just reattach to it in multiuser mode and is much more convenient this way.  It is marked as the intended method when screen is used as a login shell in the man page, and it is almost what I am doing here...

I also wanted a few additional features:

  • allow to use the scrollbars in xterm,
  • create some defaults windows,
  • define some default activity monitoring,
  • allow switching between windows using shift-tab
  • define de default escape character as control-W

Since Dustin's package symlinks .screenrc to a common file, I removed the symlink and replaced it with the following, which starts by reading Dustin's default config:

source /usr/share/screen-profiles/profiles/ubuntu.screenrc

# Allow scrolling in xterm
termcapinfo xterm ti@:te@

# if activity is detected on an affected window switched into the background
# you  will  receive the activity notification message in the status line
# the window will also be marked with an ‘@’ in the window-status display
defmonitor on

# When  any activity occurs in a background window that is being monitored
# screen displays a notification in the message line
activity "activity -> %n%f %t" # window number , flags of the window , window title

# Keybindings
# Map shift-tab to go to next window
bindkey "\033[Z" next
# Ctrl+PgUp and Ctrl+PgDn to change windows
bindkey ^[[5;5~ prev
bindkey ^[[6;5~ next**

# Start screen
screen -t motd watch -n 30 cat /etc/motd
screen -t local 0

#Escape as control-W
escape ^Ww
I am ataching this file here for easier usage.
Share this


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hi Nicolas, Perhaps over

Hi Nicolas, Perhaps over complicated, but this is what i used to test it.

if [[ $TERM != 'screen' ]] ; then
    if [[ `screen -list | grep -v "No" | awk '$2 { print }' | wc -l` == 0 ]] ; then
        screen -dr

seems that -xRR does the same

Thanks a lot for our input Dave, but it seems to me that is does about the same as screen -xRR.

Could you give it a shot and let us know?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.