Is it possible to persist the "state" of a GNU screen window (or just a standard shell) so that I can reload everything after a reboot:
- The number of opened shells
- The name of each shell
- The current directory of each shell
- The history of each shell
- If possible, their environment variables
Best Answer
It is not really possible to save a complete screen session.
What you can do is to create a proper
.screenrc
which will setup some things after you restarted your system.Here are some comments to the things you listed:
I use something like this in my
.screenrc
to open some specific shells on startup:You will get the string between '' as your window name and the command after the name will be executed on your default shell. Include any script you want, for example change in a specific directory and open some logs.
Have you ever thought about sharing the history of the shells across your sessions? IMHO this makes things much more easier. In ZSH its done with
setopt SHARE_HISTORY
in your.zshrc
If you really need this and don't want any trade-off you could think about a shell script, which reads out the current state of screen, saves the number of shells, environment variables, etc. and puts this information in a startup script called by your
.screenrc
. For me this would not be worth the effort because I appreciate a clean environment after a reboot, if I can customize the default windows for screen.