From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4406 invoked by alias); 9 May 2011 15:01:53 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16010 Received: (qmail 19155 invoked from network); 9 May 2011 15:01:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <110509080130.ZM19360@torch.brasslantern.com> Date: Mon, 09 May 2011 08:01:30 -0700 In-reply-to: Comments: In reply to Thorsten Kampe "How to redirect output without escape sequences to a file" (May 8, 9:27pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: How to redirect output without escape sequences to a file MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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. You could also create a conditional prompt, for example: PS4='%(9v.+%1N[%i]:.%F{cyan}%B+%b%f%1N[%i]%F{cyan}%B:%b%f) ' which says that if $psvar[9] has a value, then print the prompt with no coloring, otherwise use coloring. Then when you want to turn off color for a while, just assign psvar[9]=1, and when you're ready for color again, delete it with psvar[9]=(). This assumes you're not already using 9 elements of psvar in other prompts, of course.