Gnu make - determine if stdout is terminal

Trying to do:

help:
    @echo "you must $(call red_text,clean)"

      

where red_text is defined as

red_text = $(shell tput setaf 1; echo -n "$1"; tput sgr0)

      

Prints "you must clean", with "clean" printed in red.

The problem is that the output of the marker is being piped into the pipeline (for example, smaller). In this case, I shouldn't use colors, but print $ 1.

I need to update red_text

to handle the case. For this I thought I could use something like $(shell [ -t 1 ] ..)

, but the problem is that stdout is $(shell)

never a terminal.

How can I change red

to handle the case where stdout is not a terminal?

+3


source to share


2 answers


In the spirit of Perfection, not when there is nothing more to add, but when there is nothing to take away (Antoine de Saint Exupery) , solve the problem without using color first! Indeed. This sucks has its own problems. You're making assumptions about terminals that will be wrong for some poor users some fine day. You are facing this issue in an interactive terminal. You are wasting time solving a problem that could be better spent programming cool functionality instead of eye candy. You are catering to the wrong group of people, namely the chromatically dependent and ignoring the chromatically challenged, such as the red-green blind users (who are more than you and I appreciate).



+1


source


if test -t 1
then
    echo terminal
else
    echo file
fi

      



0


source







All Articles