Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to redirect output without escape sequences to a file



* Bart Schaefer (Mon, 09 May 2011 08:01:30 -0700)
> On May 8,  9:27pm, Thorsten Kampe wrote:
> } I've modified my PS4 so it contains a little bit of colour[1].
> 
> I was going to suggest that you stop using the terminal escape
> sequences directly and use the %F prompt escape instead:
> 
>     PS4='%F{cyan}%B+%b%f%1N[%i]%F{cyan}%B:%b%f '
> 
> Theoretically, these are only supposed to be output if the terminal
> supports them, so I thought that setting TERM=dumb would then turn
> off the coloring.  But no ... zsh goes for ANSI sequences if the
> terminal definition doesn't specify, so something is always output.
> 
> } Is there a way to either strip the escape sequences when redirected to
> } a file or to modify PS4 when stderr is redirected to a file?
> 
> So, the alternative is to do the stripping.  Instead of
> 
>     ... >& trace.log
> 
> use 
> 
>     ... 2>>(col > trace.log) >&2
> 
> Yes, that's somewhat inconvenient.

...and somehow not working (form me). I still got (stripped) color stuff 
in the output file ("1m33m-0m39m service:directory-agent" for instance).

"| sed 's/\x1b\[[0-9]\{1,2\}m//g'" worked for me.

How would the command line look like if wanted to pipe stdout and stderr 
to sed, and then redirect both to trace.log?

Thorsten



Messages sorted by: Reverse Date, Date, Thread, Author