zsh-users
 help / color / mirror / code / Atom feed
* view onto command pipeline?
@ 2022-07-16 16:15 Anthony Heading
  2022-07-16 21:30 ` Bart Schaefer
  0 siblings, 1 reply; 15+ messages in thread
From: Anthony Heading @ 2022-07-16 16:15 UTC (permalink / raw)
  To: zsh-users

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.






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

end of thread, other threads:[~2022-08-04 21:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-16 16:15 view onto command pipeline? Anthony Heading
2022-07-16 21:30 ` Bart Schaefer
2022-07-20 11:23   ` Anthony Heading
2022-07-20 11:37     ` Dominik Vogt
2022-07-20 12:22       ` Vincent Bernat
2022-07-20 12:35         ` Dominik Vogt
2022-07-20 19:07           ` Lawrence Velázquez
2022-07-21  0:15       ` Anthony Heading
2022-07-21  1:35         ` Lawrence Velázquez
2022-07-21  2:11           ` Anthony Heading
2022-07-21  3:15             ` Lawrence Velázquez
2022-07-21  6:43             ` Dominik Vogt
2022-08-04 21:12             ` Felipe Contreras
2022-07-20 19:27     ` Phil Pennock
2022-07-21  0:18       ` Anthony Heading

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).