Eli Schwartz <[email protected]> writes:
> On 10/9/26 12:30 AM, Collin Funk wrote:
>
>> The rationale for including the links when piped or redirected was so
>> that you could use the links when piping into 'less', for example.
>>
>> I'm leaving this report open for now, since I think we may want to
>> reconsider this due to this report and one or two similar ones.
>> Unfortunately, I am unable to link them since I haven't been able to
>> connect to bugs.gnu.org for the past week, except for a few hours
>> yesterday. :(
>
>
> Similar logic applies to color; I personally rather like LESS="-R" and
> viewing logfiles in color, but many people distinctly dislike it.
>
> And that is why ls (and many other programs) has --color=WHEN, and
> specifying auto / letting it default to such, will do isatty detection.
> I admit it seems a bit convoluted to expect users to run
>
> chroot --color=never --help
You could do this currently, which is equally, if not more, convoluted:
$ chroot () { TERM=dumb command chroot "$@"; }
> to disable bold/underline/links in help text, but I think the underlying
> principle is the same and I don't really know that I understand the
> rationale for assuming by default that it will be read by less or, more
> pertinently, that users have configured less to get output that doesn't
> look like this:
I think the assumption was that people typically be outputting to a
terminal, even if the program was piped. E.g., the following:
$ chroot --help | grep -F userspec
Would emit the option with the link included.
> Usage: ls [OPTION]... [FILE]...
> List information about the FILEs (the current directory by default).
> Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
>
> Mandatory arguments to long options are mandatory for short options too.
>
> ESC]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#ls-aESC\ESC[1m-a,
> --allESC[0mESC]8;;ESC\
> do not ignore entries starting with .
>
>
> Which is unreadable.
>
> Meanwhile, in a terminal that supports them, I can normally click on ls
> --help's hyperlinks, but piping it to less -R actually breaks that, and
> I don't know whether it's supposed to work (or how), so the feature
> simply has my heartiest shrugs.
Yes, because of that and the other reports, I think something like this
is best:
diff --git a/src/system.h b/src/system.h
index 84be742ff..5646754b5 100644
--- a/src/system.h
+++ b/src/system.h
@@ -592,10 +592,11 @@ oputs_ (MAYBE_UNUSED char const *program, char const
*option)
#endif
if (help_no_sgr == -1)
{
- /* Note we don't consult isatty() since usually you
- would want markup when piping to grep/less etc. */
- char const *term = getenv ("TERM");
- help_no_sgr = (!term || !*term || streq (term, "dumb"));
+ char const *term;
+ help_no_sgr = (isatty (STDOUT_FILENO)
+ ? (!(term = getenv ("TERM")) || !*term
+ || streq (term, "dumb"))
+ : !getenv ("IN_HELP2MAN"));
}
if (help_no_sgr)
{
But lets see what Pádraig thinks.
Collin