Is there any way to do isatty() from shell scripts?
As Junio said, test -t. :) Is there interest in me adding that feature?
I would suggest that all scripts that use colors have a
always/auto/never (with boolean fallback) option and also honor
pager.color if the pager is in use.