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

Re: trap stdout and stderr and format without adding to command line?



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.



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