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

[PATCH 2/2] help: add "man.viewer" config var to use "woman" or "konqueror"

From
Christian Couder <chriscool@tuxfamily.org>
Date
Feb 17, 2008, 19:52 UTC
Message-ID
<20080217205252.ff7ea434.chriscool@tuxfamily.org>

This patch makes it possible to view man pages using other tools than the "man" program. It also implements support for emacs' "woman" and konqueror (using the man KIO slave) to view man pages.

Note that "emacsclient" is used with option "-e" to launch "woman" on emacs and this works only on versions >= 22, but currently the "emacsclient" version is not checked.

It should also perhaps try to use kfmclient to launch konqueror in a new tab, like it's done in "git-web-browse".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 help.c |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)
	This is a first draft to know what you think about the
	idea and if you have some suggestions about testing
	emacsclient version.
diff --git a/help.c b/help.c
index 8143dcd..6b0e599 100644
--- a/help.c
+++ b/help.c
@@ -9,6 +9,7 @@
 #include "common-cmds.h"
 
 static const char *help_default_format;
+static const char *man_viewer;
 
 static enum help_format {
 	man_format,
@@ -41,6 +42,8 @@ static int git_help_config(const char *var, const char *value)
 {
 	if (!strcmp(var, "help.format"))
 		return git_config_string(&help_default_format, var, value);
+	if (!strcmp(var, "man.viewer"))
+		return git_config_string(&man_viewer, var, value);
 	return git_default_config(var, value);
 }
 
@@ -312,11 +315,38 @@ static void setup_man_path(void)
 	strbuf_release(&new_path);
 }
 
+static void exec_woman_emacs(const char *page)
+{
+	/*
+	 * FIXME: This works only with emacsclient version >= 22.
+	 */
+	struct strbuf man_page = STRBUF_INIT;
+	strbuf_addf(&man_page, "(woman \"%s\")", page);
+	execlp("emacsclient", "emacsclient", "-e", man_page.buf, NULL);
+}
+
+static void exec_man_konqueror(const char *page)
+{
+	const char *display = getenv("DISPLAY");
+	if (display && *display) {
+		struct strbuf man_page = STRBUF_INIT;
+		strbuf_addf(&man_page, "man:%s(1)", page);
+		execlp("konqueror", "konqueror", man_page.buf, NULL);
+	} else
+		execlp("man", "man", page, NULL);
+}
+
 static void show_man_page(const char *git_cmd)
 {
 	const char *page = cmd_to_page(git_cmd);
 	setup_man_path();
-	execlp("man", "man", page, NULL);
+	if (!man_viewer || !strcmp(man_viewer, "man"))
+		execlp("man", "man", page, NULL);
+	if (!strcmp(man_viewer, "woman"))
+		exec_woman_emacs(page);
+	if (!strcmp(man_viewer, "konqueror"))
+		exec_man_konqueror(page);
+	die("'%s': unsupported man viewer.", man_viewer);
 }
 
 static void show_info_page(const char *git_cmd)
@@ -363,6 +393,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
 	const char *help_cmd = argv[1];
+	int nongit;
 
 	if (argc < 2) {
 		printf("usage: %s\n\n", git_usage_string);
@@ -370,6 +401,9 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 		exit(0);
 	}
 
+	setup_git_directory_gently(&nongit);
+	git_config(git_help_config);
+
 	if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a")) {
 		printf("usage: %s\n\n", git_usage_string);
 		list_commands();
@@ -388,10 +422,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 	}
 
 	else {
-		int nongit;
-
-		setup_git_directory_gently(&nongit);
-		git_config(git_help_config);
 		if (help_default_format)
 			parse_help_format(help_default_format);
 
-- 
1.5.4.1.1384.gdeff
Next: Junio C Hamano
Message 1 of 2 in “help: add "man.viewer" config var to use "woman" or "konqueror"”
  1. 2/2 help: add "man.viewer" config var to use "woman" or "konqueror"Christian Couder, Feb 17, 2008
  2. Junio C HamanoFeb 18, 2008

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.