diff --git a/NEWS b/NEWS index e965e96eb..41011b299 100644 --- a/NEWS +++ b/NEWS @@ -70,7 +70,7 @@ GNU coreutils NEWS -*- outline -*- with bold attributes, and hyperlinks into the online manual on gnu.org. The links can be configured with the --enable-manual-url configure option, and the bold highlighting with --disable-bold-man-page-references. - At runtime all markup can be disabled by setting the HELP_NO_MARKUP env var. + At runtime all markup can be disabled by with the TERM=dumb env var value. 'fmt' -w,--width no longer includes '\n' in the width of a line. I.e., the specified width is interpreted to be an _inclusive_ maximum. diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 4a098e24e..0d7757d14 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -764,12 +764,12 @@ these programs, abbreviations of the long options are not always recognized. @item --help @opindex --help -@vindex HELP_NO_MARKUP +@vindex TERM @cindex help, online Print a usage message listing all available options, then exit successfully. Help output may be marked up with terminal codes for formatting or -hyperlinks, which can be disabled by setting the @env{HELP_NO_MARKUP} -environment variable. +hyperlinks, which can be disabled by unsetting the @env{TERM} environment +variable, or setting it to the value @samp{dumb}. @item --version @opindex --version diff --git a/man/local.mk b/man/local.mk index a34a4902c..92cfebadd 100644 --- a/man/local.mk +++ b/man/local.mk @@ -27,7 +27,8 @@ if HAVE_PERL if BOLD_MAN_REFS help2man_OPTS=--bold-refs endif -run_help2man = $(PERL) -- $(srcdir)/man/help2man --loose-indent $(help2man_OPTS) +run_help2man = env TERM=not_dumb $(PERL) -- \ + $(srcdir)/man/help2man --loose-indent $(help2man_OPTS) else run_help2man = $(SHELL) $(srcdir)/man/dummy-man endif diff --git a/man/viewman b/man/viewman index 7fb8fed9c..ee9f313b9 100755 --- a/man/viewman +++ b/man/viewman @@ -8,7 +8,6 @@ # export MANPAGER=less unset GROFF_NO_SGR -unset HELP_NO_MARKUP hdir=$(dirname "$0") diff --git a/src/system.h b/src/system.h index bf3ad620f..c6fe16750 100644 --- a/src/system.h +++ b/src/system.h @@ -542,7 +542,7 @@ is_nul (void const *buf, size_t length) /* Output --option descriptions; formatted with ANSI format and hyperlink codes. Any postprocessors like help2man etc. are expected to handle this, - though it can be disabled in edge cases with the HELP_NO_MARKUP env var. */ + though it can be disabled in edge cases with the TERM=dumb env var. */ #define oputs(option) oputs_ (PROGRAM_NAME, option) static inline void @@ -554,13 +554,20 @@ oputs_ (MAYBE_UNUSED char const* program, char const *option) #else -1; /* Lookup. */ #endif - if (help_no_sgr == 1 - || (help_no_sgr == -1 && (help_no_sgr = !!getenv ("HELP_NO_MARKUP")))) + 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")); + } + if (help_no_sgr) { fputs (option, stdout); return; } + char const* first_word = option + strspn (option, " \t\n"); char const *option_text = strchr (option, '-'); if (!option_text) diff --git a/tests/misc/getopt_vs_usage.sh b/tests/misc/getopt_vs_usage.sh index 973ad06ae..51b0324de 100755 --- a/tests/misc/getopt_vs_usage.sh +++ b/tests/misc/getopt_vs_usage.sh @@ -44,12 +44,12 @@ for prg in $built_programs; do got_option=false for opt in $(shortopts $sprg); do got_option=true - env HELP_NO_MARKUP=1 $prg --help | grep -F -- " -$opt" >/dev/null || + env $prg --help | grep -F -- " -$opt" >/dev/null || { printf -- '%s -%s missing from --help\n' $sprg $opt >&2; fail=1; } done for opt in $(longopts $sprg); do got_option=true - env HELP_NO_MARKUP=1 $prg --help | grep -F -- "--$opt" >/dev/null || + env $prg --help | grep -F -- "--$opt" >/dev/null || { printf -- '%s --%s missing from --help\n' $sprg $opt >&2; fail=1; } done test "$DEBUG" && test $got_option = false && echo No options for $prg ? diff --git a/tests/misc/usage_vs_refs.sh b/tests/misc/usage_vs_refs.sh index 0e0d111fd..ebb132a68 100755 --- a/tests/misc/usage_vs_refs.sh +++ b/tests/misc/usage_vs_refs.sh @@ -25,7 +25,7 @@ longopts() { getopts $1 | cut -s -d'"' -f2; } getopts() { skip='--help|--version' # These refs treated specially - HELP_NO_MARKUP=1 env "$1" --help | + env "$1" --help | grep -E '^( -| --)' | # find options grep -Ev -- " - |-M.*from first" | # exclude invalid matches sed -e 's/^ *//' -e's/ .*//' | # strip leading space and descriptions