Other Prevent a terminal appplication from exiting

I'd like to prevent a terminal application from closing.

Here's what often happens: I open a Python, Ruby, or Rails console. I do some testing in that console, maybe define a few functions, get a few objects from the database, etc. and then don't use it for a while, but keeping it open because I'm implementing some of the ideas I just prototyped. Then a few minutes later I want to go back to my console, only to find out I already closed it! D'oh! I have to start again.

So I would like to "pin" some application as it were. First, I tried doing this for Python with the atexit module and/or somehow catching the SystemExit error, but couldn't get that to work in the interactive shell. It's also a Python-specific solution, which won't work for irb (for example).

I then thought about doing it in the shell or tmux somehow, but the best I could think of was restarting the program after it's closed, which is of no use to me since it's too late by then.

I can't think of any way to do this, however, maybe someone else can think of something clever? I'm talking about an "intentional" exit (actually typing exit, or pressing ^D), not a SIGHUP (so trap also won't work).
 
Have you tried mosh? Additional benefit is you can connect to the session again from somewhere else.
 
I can't think of a way to save state despite intentionally exiting the terminal either. You could however alias exit(3) or similar to call a small script:
Code:
% exit
-- You may want to keep this open. Are you sure you want to exit? y/n n
%
However I could see that being a bit annoying I suppose.
 
For me tmux(1) is indispensable for avoiding that kind of problems. I always use it for processes that take some time, that I want to continue, even if I disconnect the session by accident. The process won't stop, and in any case, tmux a would bring me back to the "lost" process.
 
Back
Top