Skip to contentSkip to conversation

builtin-help: fallback to GIT_MAN_VIEWER before man

PATCH In review Romain Francoise 2 participants 2 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 builtin-help: fallback to GIT_MAN_VIEWER before man

In some situations it is useful to be able to switch viewers via the environment, e.g. in Emacs shell buffers. So check the GIT_MAN_VIEWER environment variable and try it before falling back to "man".

---

The motivation for this is that I want the viewer to be "woman" in Emacs shell buffers and "man" otherwise, and having an environment variable (like PAGER or EDITOR) is cleaner than using a man.viewer.cmd wrapper to do the redirection.

 Documentation/git-help.txt |    4 +++-
 builtin-help.c             |    3 +++
 2 files changed, 6 insertions(+), 1 deletions(-)
Documentation/git-help.txt +3 -1
index f414583..d9b9c34 100644
@@ -112,7 +112,9 @@ For example, this configuration:
 will try to use konqueror first. But this may fail (for example if
 DISPLAY is not set) and in that case emacs' woman mode will be tried.
 
-If everything fails the 'man' program will be tried anyway.
+If everything fails, or if no viewer is configured, the viewer specified
+in the GIT_MAN_VIEWER environment variable will be tried.  If that
+fails too, the 'man' program will be tried anyway.
 
 man.<tool>.path
 ~~~~~~~~~~~~~~~
builtin-help.c +3 -0
index 721038e..64207cb 100644
@@ -361,12 +361,15 @@ static void show_man_page(const char *git_cmd)
 {
 	struct man_viewer_list *viewer;
 	const char *page = cmd_to_page(git_cmd);
+	const char *fallback = getenv("GIT_MAN_VIEWER");
 
 	setup_man_path();
 	for (viewer = man_viewer_list; viewer; viewer = viewer->next)
 	{
 		exec_viewer(viewer->name, page); /* will return when unable */
 	}
+	if (fallback)
+		exec_viewer(fallback, page);
 	exec_viewer("man", page);
 	die("no man viewer handled the request");
 }
Signature · 1 line
1.6.0.1.141.g445ca.dirty
#1 lore raw
Quoted 11 lines · Romain Francoise

In some situations it is useful to be able to switch viewers via the environment, e.g. in Emacs shell buffers. So check the GIT_MAN_VIEWER environment variable and try it before falling back to "man".

---

The motivation for this is that I want the viewer to be "woman" in Emacs shell buffers and "man" otherwise, and having an environment variable (like PAGER or EDITOR) is cleaner than using a man.viewer.cmd wrapper to do the redirection.

Obviously I am biased, as I am among the people who have PAGER=cat and EDITOR=emacsclient, and 70% of whose command invocation is from within the "M-x compile", but I like this.