While modern desktop environments usually start all the applications which were open in the previous session and some terminal emulators may even open as many tabs as before, I've never seen a terminal emulator which

  • opens a shell in that directory in which its previous shell was when the terminal emulator was closed, and
  • shows the same output as before.

Technically both things should be possible:

  • The current working directory of the shell can be found via the /proc file system.
  • If the terminal emulator saves all text (including ANSI sequences) shown before its closed, it could restore that state and then start the shell in the directory it last was. If the terminal emulator also saves the state of the shell's history file at the state after the terminal has been closed, it could also make the shell load that specific history file on next startup.

Sure, there are other things like having the exit code of the previous command or the previous working directory available in a variable, but my main motivation here is to be able to continue working on the results of my previous command (e.g. a compiler run which resulted in errors or a package build which had some warnings) despite I had to exit my whole X session or even reboot the machine — without manually capturing that output which will remind me or help me to continue the work I was about to do.

So I wonder: Is there is already an terminal emulator for X which can do these things?

The case surely more difficult if other, especially text-mode applications were running in such a terminal, maybe called from within the shell. Reproducing their state is not done with just a directory name and history file.

But then again, there exist (more or less working) tools to freeze and thaw whole processes…

  • 1
    Reproducing their state is more than just painting the screen the same: the shell's memory is gone. Apr 23, 2016 at 21:28
  • 2
    As for remembering and reproducing the output from the previous run, Apple's Terminap.app does what you want. (This is not an answer because your question is tagged x11 and that application is not x11.) As for somehow re-creating the shell's history, that's way above and beyond the scope of what the terminal emulator's business is. As far as the terminal emulator is concerned, the program running inside the terminal may not even be a (normal) shell anyway! Plus, shells already have features to save and restore history, don't they?
    – Celada
    Apr 23, 2016 at 21:34
  • 2
    What about GNU screen?
    – Guido
    Apr 23, 2016 at 22:34
  • 2
    Even if the terminal is running a shell, the whole purpose of a shell is to run other programs, so you'd have to check for children of the shell and figure out how to restore them too. Your "modern desktop environment" applications, though they are larger than a shell, are not as general, so saving their state is easier (maybe not easy, but easier).
    – user41515
    Apr 24, 2016 at 0:29
  • 2
    See unix.stackexchange.com/q/3056/121614 and in particular unix.stackexchange.com/a/58490/121614. That uses screen to accomplish most of your requirements, except the 'repainting'.
    – NZD
    Apr 24, 2016 at 7:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.