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

Re: view onto command pipeline?



On 2022-07-20 at 07:23 -0400, Anthony Heading wrote:
> On Sat, Jul 16, 2022, at 5:30 PM, Bart Schaefer wrote:
> > You need to look at the preexec hook.
> 
> Ah, many thanks Bart!  Much appreciated.  Don't know how I missed that.
> 
> For the record, I used just the following, and it works great. 
> 
> git () {
>         local opts=() 
>         if [[ -o interactive && ( -t 1 || -n $pager ) ]]
>         then
>                 opts=(-c color.ui=always) 
>         fi
>         command git $opts $@
> }

So, "if invoked from shell, use color if stdout is a tty, otherwise
don't".  Since ancient Git (1.8.4) automatic-based-on-tty is the
default, so you'll need `git config --global color.ui false` run to
populate your gitconfig file to disable color normally.

The shell wrapping is simply:

    function git { command git -c color.ui=auto "$@" }

and only define this for interactive shells, so in .zshrc or the like,
not .zshenv.

-Phil




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