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:
- The number of opened shells
- The name of each shell
- The current directory of each shell
I use something like this in my .screenrc
to open some specific shells on startup:
## set the default shell
shell zsh
# screens
screen -t 'zsh'
screen -t 'mutt' mutt
screen -t 'zsh' /home/user/bin/scriptToRun
[..]
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.
- The history of each shell
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 possible, their environment variables
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.
Assuming you're using bash and accidentally closes the shell with Ctrl-D, you can
export IGNOREEOF=1
This will give you a warning and require you to press Ctrl-D twice, or type exit instead.
Best Answer
If you've set environment variables on one screen (say running bash), and then open a new screen, it is a separate bash process and therefore will not pick up the environment on the separate already running bash shell. A quick fix to get around the issue would be:
then once you've Ctrlac to get a new shell you can then
It's hacky and I use
env TERMCAP= env
because the TERMCAP environment variable is multi-line and makes thesed
far more complicated. It's not pretty, but it works :)You may want to change it to do:
So the variables are also exported.