How to save GNOME Terminal contents with ANSI escape codes?
VT100 terminals have a relatively simple way to save terminal contents with escape codes to a file using Meta-p:
XTerm.VT100.printAttributes: 2
XTerm.VT100.printerCommand: cat - > file
XTerm.VT100.translations: #override Meta <KeyPress> P: print() \n
I've looked around quite a bit, and can't find a solution for this to work in the default GNOME Terminal + XTerm + Bash.
I do not want just an image with the contents of the window.
It looks like GNOME Terminal might eventually get a fix for this, but there's no information about which version it will be included in, and it's been almost three years since the last update...
Solution 1:
Unfortunately, l0b0 the answer out of the box is: This is not possible.
In my other answer, I listed how to use script to do this, though there are some differences as you noted. The other way is to compile the source or use an unstable version.
Gnome Terminal Source Tarball
The version in Raring is 3.6.1, so you can look at this source. Inside of Terminal-window.c on line 115:
/*
* We don't want to enable content saving until vte supports it async.
* So we disable this code for stable versions.
*/
#include "terminal-version.h"
#if (TERMINAL_MINOR_VERSION & 1) != 0
#define ENABLE_SAVE
#else
#undef ENABLE_SAVE
#endif
#endif
Options:
- Add #define ENABLE_SAVE under this.
- Modify the version to an unstable.
- Download an unstable version of the .DEB.
Hope this helps.
Solution 2:
Unfortunately, l0b0 the answer out of the box is: This is not possible.
There are two ways you can attempt to rectify this, by running script at all times on your terminal and logging all output. Open up gnome-terminal, go to Edit->Profile Preferences, then the tab Title and Command and for your custom command use this:
bash -l -c 'script -q -c bash $HOME/sessionlogs/$BASHPID.sessionlog.$(date +%Y%m%d-%H%M).txt'
Make sure 'sessionlogs' exists under $HOME.
The other way has been removed and added as a second answer on this question.