10

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...

l0b0
  • 9,271

6 Answers6

4

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:

  1. Add #define ENABLE_SAVE under this.
  2. Modify the version to an unstable.
  3. Download an unstable version of the .DEB.

Hope this helps.

LimpingNinja
  • 712
  • 4
  • 8
3

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.

LimpingNinja
  • 712
  • 4
  • 8
0

You can run your shells via script(1) to get all input and output of the terminal stored in a file, including terminal escapes.

geirha
  • 47,279
0

There's a package that's called screen - a terminal multiplexor with VT100/ANSI terminal emulation.

According to the manpage of screen on the Ubuntu Manuals website , screen claims to be

a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells).Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets) a terminal multiplexor with VT100/ANSI terminal emulation'.

and when running screen:

Ctrl ah (hardcopy) Write a hardcopy of the current window to the file "hardcopy.n".

I tried in the GNOME Terminal, running screen and typing Ctrl ah

running screen and typing Ctrl Alt h

This is the output of my hardcopy.1 file when opened in Gedit:

hardcopy.1 opened in Gedit

You can find screen is in the raring/main software repository of Ubuntu 13.04.

It's not installed by default.

-1

Hm, this will not copy the escape codes, but just to grab the text, you can go to menu Edit -> Select All, then press CtrlShiftC and either (i) paste the clipboard to an editor or (ii) type cat > filename and press CtrlShiftV.

January
  • 37,208
-1

man history look for history expansion for escaped characters. I believe history can do what youre asking.

j0h
  • 15,365