How to persist `gnu screen` layout after restart

Default layout for new screen's

Manage your regions, then execute code inside screen:

  • To save your current layout to file .screen_layout:

    rm -f $HOME/.screen_layout
    screen -X layout dump .screen_layout
    
  • To make it auto-loading with layout saving:

    echo source .screen_layout  >> $HOME/.screenrc
    echo layout save def >> $HOME/.screenrc
    

How it works

  1. You type screen.
  2. Screen reads $HOME/.screenrc:
  3. source .screen_layout - read and execute commands from $HOME/.screen_layout
    Regions now created.
  4. layout save def - save current regions as layout to keep it when you detach.

layout dump .screen_layout

  • Dump (append) current layout to file in $HOME directory

screen -X command

  • Run command in current screen session (if executed inside).
    Similar to ctrla then : command

You may also

  • Disable copyright notice at startup:

    echo startup_message off >> $HOME/.screenrc
  • Increase scroll buffer(def. 100)

    echo defscrollback 1000 >> $HOME/.screenrc
  • Write own .screen_layout (50% / 50% vertical, with 2 shells):

    split -v
    screen -t s1
    
    focus
    screen -t s2
    
    focus
    

Ctrl-a then : then layout save default Provided screen is newer version (with layout feature) Good luck.

UPDATE: Here is the .screenrc file that will make the change permanent, along with adding other nice features.


"layout autosave on" works only for explicitly named layouts in .screenrc.

Namely, if you specified some layout as ABC, switched to it within Screen session and detached, this last layout will be restored after the session is resumed.

If you did not specify any layout in the configuration file, you have to run internal command "layout save your_layout_name" before detaching.

This is a .screenrc with predefined layouts to choose from:

 0 — one (the only region)
 1 — two-v (the screen is splitted vertically into two regions, default layout)
 2 — two-h (the screen is splitted horizontally into two regions)
 3 — three (three regions — two in the upper part of the screen and one underneath)
 4 — four (four regions)

Predefined layouts

Once selected from within the Screen these layouts are preserved upon detachment until the next resuming of the session (due to "layout autosave on" command).

If you've built your own layout it must be saved with "layout dump filename" command. Then you can use a code from "filename" file to add your layout in #layouts section of this .screenrc to select from.

By default "two-v" layout is loaded with the only window with bash.