2

OS X has this. Ideally I would like the reboot to appear as if it never happened from the POV of the terminal (let's ignore remote sessions and assume 0 background processes for now). Meaning, I would like to see the stdin, stdout, stderr (i.e. scrollback) history in each of my terminal tabs.

NOTE: This is NOT about bash history. This is about persisting terminal sessions between reboots.

  • It seems to me that you want the functionality, that is provided by hibernation (and it is available with Ubuntu). – sudodus Jun 16 '17 at 21:31
  • @sudodus No, not exactly. I want my terminal application to be able to manage its own persistence across my machine's state independent of hibernation, just like Chrome does for example. – theanine Jun 16 '17 at 21:55
  • I see. Sorry, but I don't know if there is a terminal window tool, that can do it. – sudodus Jun 16 '17 at 22:06
1

No, at least in gnome-terminal and other VTE-based emulators it's not possible in an implicit and convenient way.

(You can, of course, explicitly go through all your tabs before the reboot, "Select All" and copy-paste the contents into files, and view those files with some viewer after the reboot. If I understand you, this is not what you're looking for. Also, colors and other formatting would be lost.)

VTE, the terminal emulation widget behind gnome-terminal and many other terminal emulators stores most of the scrollback contents (not the latest bits, though) in temporary files under /tmp by default. The major design decisions that prevent doing what you're looking for are:

  • These files are unlinked right after being created. This is so that they are automatically removed (and the disk space is freed up) even if the terminal emulator exits uncleanly for whatever reason. In order to preserve them, they should be linked back to the filesystem tree (I don't know if it's possible) or copied into another file (which is a slow action if the scrollback is large, let alone properly handling potentially running out of disk space).

  • The files are under /tmp which is wiped out by many distros upon a reboot. A different, persistent location should be chosen instead, or some cooperation is needed with the boot scripts.

  • These files are encrypted (as of VTE version 0.40) to overcome the privacy issue of data leakage in case someone gets access to the disk. The encryption key is only available in gnome-terminal's memory. In order for these files to persist, either the encryption layer should be skipped (bringing back the old privacy concerns), or the keys should be placed on the disk at least temporarily for the duration of the reboot (... er, until that user logs in again and starts up gnome-terminal again... doesn't sound too much better). Feasible only if you don't care about privacy, or if the filesystem is guaranteed to be encrypted.

There are other smaller issues to be addressed as well, e.g. flushing incomplete blocks of these files that contain the last bits of the scrollback data.

I hope I could outline some of the design decisions VTE took that prevent doing what you're looking for. I can't see how your request could be addressed while keeping the current design goals as well. Maybe there's another terminal emulator that does what you're looking for, presumably sacrificing some of VTE's features; I don't know.

  • Aside from gnome-terminal, is there another terminal that offers anything like this? – theanine Jun 16 '17 at 21:26
0

I suggest using the very useful screen tool. It is well worth learning. Repeating in summary an answer I have put on another question:

See in the .screenrc you can initiate default windows with a custom command so you could restore sessions using different .screenrc files if you wish to restore different sessions. screen -t .... See gnu.org Screen Manual - startup files

One good way of having terminal sessions that persist is to run a 'screen' session on server. A 'screen' session gives you multiple windows on that server where you can be logged in to other machines or whatever. You can have multiple 'screen' sessions running on server. You can disconnect and reconnect to the sessions you need. 'screen' is old-school command-line keyboard but well worth learning and playing with to learn how it works. It has a few big advantages:

  • easy to install, runs on any unix(or cygwin), no graphics needed (besides terminal text graphics)
  • gives persistent windowed terminal sessions (as long as server is not rebooted)

* screen quickstart *

RTFM: gnu.org Screen User's Manual

  • screen - Run screen to create a new session simply
  • screen -ls - list screen sessions running
  • screen -r 20229.pts-2.bangor - re-attach to session

The * screen ESCAPE char by default is Ctrl-a * unless some craZy looper has changed it in .screenrc e.g. "escape ^Zz" for people who don't value process backgrounding control. To get a real Ctrl-a to terminal (goto beginning of line) if running in screen then just do Ctrl-a Ctrl-a.

  • ESCAPE c - create new screen window
  • ESCAPE 0 (or 1 2 3 4 5 6 7 8 9) - switch to window 0 (or 1 2 . . )
  • ESCAPE p or ESCAPE n - switch to previous or next window
  • ESCAPE " - window list
  • ESCAPE h - shows screen help

In full here on another question I have put in example of screen help page, command-line usage and example .screenrc:

Terminal emulator with a “restore session” feature like Mac Terminal

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.