Is there any way to activate/deactivate the logging of all input and output on a zsh session?

I am using oh-my-zsh with a customized prompt with colors, etc. and I would like to preserve all of these as possible (so that I can later open the log file in Emacs or less and have them re-parse the ansi color escape codes)

Does zsh provide any functionality to facilitate this type of logging?

Later on, what would be the best way to visualize the log files in Emacs (or some other editor) and have it properly parse all the ansi color escape codes?


The simplest way to do this would be to use script.

script is a utility which can create a TTY and then launch a program in that TTY. All output from that TTY can be logged to a file as well. It will log the raw data, including ANSI escapes.
When not given a specific command to execute, it will spawn a new shell. You can use this shell as normal, and then just exit the shell when you're done.

For example

script /tmp/mylog

And when you're done, just use CTRL+D or exit to leave the shell.


Use screen. To quote from the man page:

   C-a H       (log)         Begins/ends logging of the current window  to
                             the file "screenlog.n".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.