Linux – How to persist `gnu screen` layout after restart

gnu-screenlinux

I am using the screen split in 3 with vim on the left, and two other screens split horizontally on the right. I know that when detaching from a screen, I can save the layout with :layout save my_layout_name.

I already have layout autosave on in my .screenrc file, but that doesn't help with my issue.

How can I persist a screen's layout between different terminal sessions, and after pc restart? Or maybe as a workaround, is there a way to run screen (parameters) which split it, set up the bash on every window and save the layout?

Best Answer

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