Use script
to make a typescript of terminal session.
Then use sed
to sanitise it.
E.g;
% script mysession
% ssh user@host
[some stuff]
% exit
Script done, output file is mysession
% sed -e '
s/'`echo "\033"`'\[[[:digit:]]*\(;[[:digit:]]*\)*[[:alpha:]]//g; # ANSI Escape sequences (perhaps over-generalised)
s/[^[:print:]]//g; # Non-printable
' mysession > mysession.txt
You should now be able to read mysession.txt
without the ANSI escape codes and other non-printable characters.
This could be enhanced to delete the character before a ^H, et cetera, but you specified that you didn't want that.
Perl has a a lackluster colordiff wrapper for diff, but I prefer grc (generic colorizer).
With grc (generic colorizer), you can write your own wrappers for different types of commands or inputs (if you like that sort of thing).
Below, grc
is running against /var/log/syslog
(in the config, this file is set to a certain color scheme), where it highlights processes, pids, IPs and "connect"s.
Of course, it is recommended to use an alias so you don't forget:
alias diff="/usr/bin/grc /usr/bin/diff"
If you have git, you may just want to use that, which allows very robust diff
ing, even across branches.
git diff master:cogs/foo.txt branch:widgets/bar.txt
You do not have to use git diff
within a repository, you can use it for just regular files.
git diff old.txt new.txt
As always, you can alias diff
for ease of use.
alias diff="git diff"
Best Answer
It appears that if you select text in the Terminal, then copy it, then paste it into an application that supports rich text (e.g. Mail, TextEdit, Word), then the text color will be preserved.
It appears that in Mail and TextEdit, the background color of the terminal is also pasted; in Word, it is not. I'm not sure how to explain this discrepancy.