git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RE: [PATCH v7] help: colorize man pages if man.color=true under less(1)

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jun 21, 2021, 15:59 UTC
Message-ID
<60d0b75c80635_105b452089b@natae.notmuch>
In-Reply-To
<patch-1.1-a950ef49e28-20210621T083254Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 67 quoted lines
> From: Felipe Contreras <felipe.contreras@gmail.com>
> 
> We already colorize tools traditionally not colorized by default, like
> diff and grep. Let's do the same for man, but only if `color.man` is
> explicitly set to "true".
> 
> Unlike other `color.*` output this colorization is not enabled by
> `color.ui` being true, the user needs to explicitly set the
> `color.man` variable to `true.
> 
> When it was proposed to treat `color.man` like any other `color.*`
> variable some thought that git opting in coloring for an external
> program such as man(1) was a step too far[1], even if the user invoked
> it via the "git help <topic>" wrapper.
> 
> So let's make this explicitly opt-in for now. As noted in the
> documentation we're leaving ourselves an out to turn this on by
> default in the future, or e.g. putting it under the
> feature.experimental umbrella. We probably won't, but let's not
> promise users that `color.man` will forever be a special-case.
> 
> As for what this actually does the effect of having this enabled is
> that a documentation blurb like (some parts elided with "[...]"):
> 
> 	NAME
> 	----
> 	git-config - Get and set [...]
> 
> 	SYNOPSIS
> 	--------
> 	[...]
> 	'git config' [<file-option>] [...]
> 	[...]
> 	The `--type=<type>` option instructs 'git config' to ensure [...]
> 
> Will have "NAME" and "SECTION" shown as BOLD RED instead of BOLD, "git
> config" and other '-quoted parts in BLUE UNDERLINE instead of
> UNDERLINE, and `--type=<type>` and other `-quoted parts in RED BOLD
> instead of BOLD. The "Standout" setting is then used for the user's
> own search bar (invoked with "/") and prompt. See [2] for more
> examples
> 
> Normally check_auto_color() would check the value of `color.pager`, but
> in this particular case it's not git the one executing the pager, but
> man. Therefore we need to check pager_use_color ourselves.
> 
> We do not need to support `color.man` being set to `always`; The `git
> help` command is always run for a tty (it would be very strange for a
> user to do `git help $page > output`, but in fact, that works anyway,
> we don't even need to check if stdout is a tty, but just to be
> consistent we do). So it's simply a boolean in our case.
> 
> So, in order for this change to have any effect:
> 
>  1. color.man=true must be set in the config
>  2. The user must use less
>  3. Not have the same LESS_TERMCAP variables set (we call setenv(3) with overwrite=0)
>  4. Have color.ui enabled
>  5. Not have color.pager disabled
>  6. Not have git with stdout directed to a file
> 
> 1. https://lore.kernel.org/git/87tun1qp91.fsf@evledraar.gmail.com/
> 2. https://unix.stackexchange.com/questions/119/colors-in-man-pages/147
> 
> Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Looks good to me.
-- 
Felipe Contreras
Previous: Felipe ContrerasNext: Jeff King
Message 16 of 22 in “help: colorize man pages”
  1. help: colorize man pagesFelipe Contreras, May 23, 2021
  2. Phillip WoodMay 24, 2021
  3. Felipe ContrerasMay 24, 2021
  4. Ævar Arnfjörð BjarmasonJun 8, 2021
  5. Junio C HamanoJun 8, 2021
  6. Felipe ContrerasJun 8, 2021
  7. help: colorize man pages if man.color=true under less(1)Ævar Arnfjörð Bjarmason, Jun 21, 2021
  8. Phillip WoodJun 21, 2021
  9. Junio C HamanoJun 21, 2021
  10. Felipe ContrerasJun 21, 2021
  11. Ævar Arnfjörð BjarmasonJun 21, 2021
  12. Jeff KingJun 23, 2021
  13. Felipe ContrerasJun 24, 2021
  14. Junio C HamanoJun 28, 2021
  15. Felipe ContrerasJun 28, 2021
  16. Felipe ContrerasJun 21, 2021
  17. Jeff KingJun 24, 2021
  18. Junio C HamanoJun 29, 2021
  19. Felipe ContrerasJun 29, 2021
  20. Felipe ContrerasJun 24, 2021
  21. help: add option to colorize man pages under lessFelipe Contreras, Jun 26, 2021
  22. Ævar Arnfjörð BjarmasonJun 26, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.