git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: "Junio Hamano" <junkio@cox.net>, "Pascal Obry" <pascal@obry.net>,
	"Xavier Maillard" <xma@gnu.org>
Cc: git@vger.kernel.org
Subject: [PATCH 3/5] help: use "man.<tool>.cmd" as custom man viewer command
Date: Fri, 25 Apr 2008 08:24:58 +0200	[thread overview]
Message-ID: <20080425082458.bfc113ac.chriscool@tuxfamily.org> (raw)

Currently "git help -m GITCMD" is restricted to a set of man viewers
defined at compile time. You can subvert the "man.<tool>.path" to
force "git help -m" to use a different man, viewer, but if you have a
man viewer whose invocation syntax does not match one of the current
tools then you would have to write a wrapper script for it.

This patch adds a git config variable "man.<tool>.cmd" which allows a
more flexible man viewer choice.

If you run "git help -m GITCMD" with the "man.viewer" config variable
set to an unrecognized tool then it will query the "man.<tool>.cmd"
config variable. If this variable exists, then the specified tool will
be treated as a custom man viewer and it will be run in a shell with
the man page name of the GITCMD added as extra parameter.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 help.c |   58 ++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/help.c b/help.c
index 7373aa2..eb13e9a 100644
--- a/help.c
+++ b/help.c
@@ -160,7 +160,15 @@ static void exec_man_man(const char* path, const char *page)
 	warning("failed to exec '%s': %s", path, strerror(errno));
 }
 
-static void do_add_man_viewer(const char *name)
+static void exec_man_cmd(const char *cmd, const char *page)
+{
+	struct strbuf shell_cmd = STRBUF_INIT;
+	strbuf_addf(&shell_cmd, "%s %s", cmd, page);
+	execl("/bin/sh", "sh", "-c", shell_cmd.buf, NULL);
+	warning("failed to exec '%s': %s", cmd, strerror(errno));
+}
+
+static void add_man_viewer(const char *name)
 {
 	struct man_viewer_list **p = &man_viewer_list;
 	size_t len = strlen(name);
@@ -178,16 +186,6 @@ static int supported_man_viewer(const char *name, size_t len)
 		!strncasecmp("konqueror", name, len));
 }
 
-static int add_man_viewer(const char *value)
-{
-	if (supported_man_viewer(value, strlen(value)))
-		do_add_man_viewer(value);
-	else
-		warning("'%s': unsupported man viewer.", value);
-
-	return 0;
-}
-
 static void do_add_man_viewer_info(const char *name,
 				   size_t len,
 				   const char *value)
@@ -207,7 +205,23 @@ static int add_man_viewer_path(const char *name,
 	if (supported_man_viewer(name, len))
 		do_add_man_viewer_info(name, len, value);
 	else
-		warning("'%s': path for unsupported man viewer.", name);
+		warning("'%s': path for unsupported man viewer.\n"
+			"Please consider using 'man.<tool>.cmd' instead.",
+			name);
+
+	return 0;
+}
+
+static int add_man_viewer_cmd(const char *name,
+			      size_t len,
+			      const char *value)
+{
+	if (supported_man_viewer(name, len))
+		warning("'%s': cmd for supported man viewer.\n"
+			"Please consider using 'man.<tool>.path' instead.",
+			name);
+	else
+		do_add_man_viewer_info(name, len, value);
 
 	return 0;
 }
@@ -225,6 +239,11 @@ static int add_man_viewer_info(const char *var, const char *value)
 			return config_error_nonbool(var);
 		return add_man_viewer_path(name, subkey - name, value);
 	}
+	if (!strcmp(subkey, ".cmd")) {
+		if (!value)
+			return config_error_nonbool(var);
+		return add_man_viewer_cmd(name, subkey - name, value);
+	}
 
 	warning("'%s': unsupported man viewer sub key.", subkey);
 	return 0;
@@ -241,7 +260,8 @@ static int git_help_config(const char *var, const char *value)
 	if (!strcmp(var, "man.viewer")) {
 		if (!value)
 			return config_error_nonbool(var);
-		return add_man_viewer(value);
+		add_man_viewer(value);
+		return 0;
 	}
 	if (!prefixcmp(var, "man."))
 		return add_man_viewer_info(var, value);
@@ -543,16 +563,18 @@ static void setup_man_path(void)
 
 static void exec_viewer(const char *name, const char *page)
 {
-	const char *path = get_man_viewer_info(name);
+	const char *info = get_man_viewer_info(name);
 
 	if (!strcasecmp(name, "man"))
-		exec_man_man(path, page);
+		exec_man_man(info, page);
 	else if (!strcasecmp(name, "woman"))
-		exec_woman_emacs(path, page);
+		exec_woman_emacs(info, page);
 	else if (!strcasecmp(name, "konqueror"))
-		exec_man_konqueror(path, page);
+		exec_man_konqueror(info, page);
+	else if (info)
+		exec_man_cmd(info, page);
 	else
-		warning("'%s': unsupported man viewer.", name);
+		warning("'%s': unknown man viewer.", name);
 }
 
 static void show_man_page(const char *git_cmd)
-- 
1.5.5.130.g3ab1e.dirty

                 reply	other threads:[~2008-04-25  6:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080425082458.bfc113ac.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=pascal@obry.net \
    --cc=xma@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).