zsh-users
 help / color / mirror / code / Atom feed
* trap stdout and stderr and format without adding to command line?
@ 2011-06-29  2:42 Trevor Wennblom
  2011-06-29  7:34 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Trevor Wennblom @ 2011-06-29  2:42 UTC (permalink / raw)
  To: zsh-users

Hello,

I'm attempting to find a way to arbitrarily format stdout and stderr by default.

Essentially:

% ls
  [stdout]  file00  file03  file06  file09  file12  file15  file18
  [stdout]  file01  file04  file07  file10  file13  file16  file19
  [stdout]  file02  file05  file08  file11  file14  file17
%

The closest I've gotten is Jeroen van Wolffelaar's annotate script[1] and trying to wrap it with preexec (where much learning occurred and adventure was had).

I'm guessing I could compile a custom shell to always prefix the command with the annotate script. Alternately could stdout/stderr be modified by the shell itself?

Second question, somewhat related. I noticed the annotate script would treat output differently. For instance; stripping coloring, treating 'ls -C' like 'ls -1', etc.

trevor

[1]: http://jeroen.a-eskwadraat.nl/sw/annotate/annotate

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: trap stdout and stderr and format without adding to command line?
  2011-06-29  2:42 trap stdout and stderr and format without adding to command line? Trevor Wennblom
@ 2011-06-29  7:34 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2011-06-29  7:34 UTC (permalink / raw)
  To: zsh-users

On Jun 28,  9:42pm, Trevor Wennblom wrote:
} 
} I'm attempting to find a way to arbitrarily format stdout and stderr
} by default.

I suggest you read the thread around these posts:

http://www.zsh.org/mla/users/2011/msg00358.html
http://www.zsh.org/mla/users/2011/msg00361.html

Although not exactly the same question, it will give you some idea of
the complications you're up against.  

} I'm guessing I could compile a custom shell to always prefix the
} command with the annotate script.

If you're only worried about doing this from interactive shells, some
zle widget programming (override accept-line, for example) may suffice.

} Alternately could stdout/stderr be modified by the shell itself? 

Generally speaking, no, or at least not without potentially changing
the behavior of the commands (see your next question).  You'd want to
exclude programs such as editors that expect to interact, etc.

} Second question, somewhat related. I noticed the annotate script would
} treat output differently.  For instance; stripping coloring, treating
} 'ls -C' like 'ls -1', etc.

It doesn't "strip" anything -- the commands themselves are noticing that
the output is not a terminal, and altering their behavior accordingly.

If you want to do this transparently, you need to at least be using the
zsh/zpty module -- see Functions/Misc/nslookup, for example.  E.g. if
you want to prefix every line with "  [stdout]  " you could create a
zpty terminal that is 12 columns narrower than your actual terminal,
so that the output would leave enough space.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-29  7:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-29  2:42 trap stdout and stderr and format without adding to command line? Trevor Wennblom
2011-06-29  7:34 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).