[GnuScreen] What laughs at “script”? :)

GnuScreenHave you ever tried to capture a terminal session using “script” for a tutorial you were writing only to find, when you were done that there were unreadable characters and manual removal was too tedious? Or, using “col -bx < file1.txt > file1.txt.bak” only did half the work? Most people with colorful terminals and fancy prompts run into this problem:)

If you would like to really make a typescript of your terminal session and have everything intact, without hassels, then let GnuScreen do the job.

1) Set a decent scrollback buffer

My screenrc file, ~/.screen.rc, has the following:

caption always “%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<”
defscrollback 90000

“caption always” will display a caption at the bottom of every screen windows. This is very useful as it lets you know which screen-window is currently in use.

“defscrollback 90000” Allows the scrollback buffer to recall 90000 lines of text! To see just how much data can be recalled I did a simple test. The test consisted of writing 80-characters per line, 90000 times to a text file, “test.txt”, then doing “du -k test.txt”.

Generating data with the commands “jot” and “rs”:

swinful@thinkpad> foreach line ( `jot – 1 90000` )
foreach? echo `jot -r -c 160 a z | rs -g 0 80` >>! test.txt
foreach? end

swinful@thinkpad> du -k test.txt
14256   test.txt

If you need to retain more than 14MB of data, then a scroll-back buffer of 90000 will not be enough.

2) Start Screen and begin typing

3) Dump the whole scrollback  buffer

Create the bufferfile,  ‘/tmp/screen-exchange’, while in screen:  C-a :bufferfile

Copy the scrollback buffer to: C-a [ g SPACE G $ >

Paste the scrollback buffer to: ‘/tmp/screen-exchange’: C-a >

cp ‘/tmp/screen-exchange’ to ~/some-file.txt

This entry was posted in *Nix. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s