A working draft for a traditional shell:
ttyid=$(readlink /proc/$$/fd/1)
\___/ \______/ \___/ | | |
| | | | | \- 0: stdin
| | | | | 1: stdout <- our interest
| | | | | 2: stderr
| | | | \- fd is, maybe, filedescriptor
| | | |
| | | \- $$ is the PID of the current process (shell,
| | | in our case)
| | |
| | \- you know, much runtime stuff is here
| |
| \- readlink extracts the symbolic link of /proc/$$/fd/1
| lrwx------ 1 stefan stefan 64 2011-03-18 09:11
| /proc/22159/fd/1 -> /dev/pts/4
|
\- /dev/tty3 for real shell, /dev/pts/3 for xterm
Now we can cat the screen to a file. Needs sudo.
id=${ttyid//\/dev\/tty}
sudo cat /dev/vcs$id > screen.dump
Apropos screendump: so named program doesn't work for me any more. Maybe for older kernels only. /dev/pts/N didn't work for me too. Maybe you have to some optional MKDEV in /dev - I remember darkly about some /dev/cuaN, but I may be wrong.
We would like to pipe the output instead of using screen.dump. But somehow it doesn't work - sometimes it waits for ENTER.
The capturing isn't a normal textfile with linefeeds, but with - for example - 80x50 chars in one sequence.
To pick the last 2 lines, 1 for the output of the command, and one for the prompting line, I revert it, pick 160 chars, revert again and pick 80.
rev vcs4.dat | sed 's/\(.\{160\}\).*/\1/g' | rev | sed 's/\(.\{80\}\).*/\1/g'
Just in case you ever wondered, why there is a rev program.
Critique:
- The first commands are entered, thus moving the line ahed. Well - just a numerical excercise to pick the 3rd-last line or something. I worked mainly in a different window.
- Not everybody has a 80x50 screen. Well, yes, we know. There is $COLUMNS and $ROWS for your pleasure.
- The output is not allways at the bottom. A fresh and young shell might be in the upper rows. Well - simple as that: Evaluate what shell is running. Which prompt is used. Do some prompt detection and find the last line with a shell-prompt. The line before (or 2. before) should contain the directory.
The first diagram is made with explain.py
/dev/tty, but it should be possible to capture anything sent tostdoutorstderr, which might be adequate. – Mikel Mar 10 '11 at 20:26scriptutility that logs all terminal output. And there's also Emacs; see the related question Would it be possible to jump between prev/next command prompts?. – Gilles Mar 16 '11 at 19:42