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

view onto command pipeline?



I'm trying to wrap 'git' in a shell function to better anticipate when I want colour output.  Which is probably something like "when run from the command line and outputting to a tty or piped a pager, but not when piped to anything else".

The condition seems to make this difficuult post-shell;  while most (all?) of the coloured command support an isatty() test, the traditional ways of commandeering that with pty pairs or LD_PRELOAD or whatever seem no use by themselves without knowing more about the pipeline.   I vaguely built a solution by ferreting about in /proc and using lsof to follow the stdout chain to identify a pager, but that feels misguided.

Is there a zsh way to solve this?  Perhaps just by pattern matching on the command buffer to see if it has "| less" toward the end?  I couldn't find any shell variables that show the current pipeline string,  also found history appears to be written too late to introspect that?

I'd be fine to wrap the pager as well, if there is any way to convey some flag backwards up the pipeline...  but I think by the time that is evaluated everything is running totally concurrently in different subshells, so probably that can't work.








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