@matheusbsbs / matheus-bagliano / commits / a26a06afed
Fork 0

help: use "man.<tool>.cmd" as custom man viewer command

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Apr 25, 2008 at 08:24 UTC a26a06afed783cb7cf7207c1bcb2d1781d623d1e
1 file changed +40 -18
help.c
+40 -18
@@ -163,7 +163,15 @@ static void exec_man_man(const char* path, const char *page)
163 warning("failed to exec '%s': %s", path, strerror(errno));
164 }
165
166 -static void do_add_man_viewer(const char *name)
166 +static void exec_man_cmd(const char *cmd, const char *page)
167 +{
168 + struct strbuf shell_cmd = STRBUF_INIT;
169 + strbuf_addf(&shell_cmd, "%s %s", cmd, page);
170 + execl("/bin/sh", "sh", "-c", shell_cmd.buf, NULL);
171 + warning("failed to exec '%s': %s", cmd, strerror(errno));
172 +}
173 +
174 +static void add_man_viewer(const char *name)
175 {
176 struct man_viewer_list **p = &man_viewer_list;
177 size_t len = strlen(name);
@@ -181,16 +189,6 @@ static int supported_man_viewer(const char *name, size_t len)
189 !strncasecmp("konqueror", name, len));
190 }
191
184 -static int add_man_viewer(const char *value)
185 -{
186 - if (supported_man_viewer(value, strlen(value)))
187 - do_add_man_viewer(value);
188 - else
189 - warning("'%s': unsupported man viewer.", value);
190 -
191 - return 0;
192 -}
193 -
192 static void do_add_man_viewer_info(const char *name,
193 size_t len,
194 const char *value)
@@ -210,7 +208,23 @@ static int add_man_viewer_path(const char *name,
208 if (supported_man_viewer(name, len))
209 do_add_man_viewer_info(name, len, value);
210 else
213 - warning("'%s': path for unsupported man viewer.", name);
211 + warning("'%s': path for unsupported man viewer.\n"
212 + "Please consider using 'man.<tool>.cmd' instead.",
213 + name);
214 +
215 + return 0;
216 +}
217 +
218 +static int add_man_viewer_cmd(const char *name,
219 + size_t len,
220 + const char *value)
221 +{
222 + if (supported_man_viewer(name, len))
223 + warning("'%s': cmd for supported man viewer.\n"
224 + "Please consider using 'man.<tool>.path' instead.",
225 + name);
226 + else
227 + do_add_man_viewer_info(name, len, value);
228
229 return 0;
230 }
@@ -228,6 +242,11 @@ static int add_man_viewer_info(const char *var, const char *value)
242 return config_error_nonbool(var);
243 return add_man_viewer_path(name, subkey - name, value);
244 }
245 + if (!strcmp(subkey, ".cmd")) {
246 + if (!value)
247 + return config_error_nonbool(var);
248 + return add_man_viewer_cmd(name, subkey - name, value);
249 + }
250
251 warning("'%s': unsupported man viewer sub key.", subkey);
252 return 0;
@@ -244,7 +263,8 @@ static int git_help_config(const char *var, const char *value)
263 if (!strcmp(var, "man.viewer")) {
264 if (!value)
265 return config_error_nonbool(var);
247 - return add_man_viewer(value);
266 + add_man_viewer(value);
267 + return 0;
268 }
269 if (!prefixcmp(var, "man."))
270 return add_man_viewer_info(var, value);
@@ -546,16 +566,18 @@ static void setup_man_path(void)
566
567 static void exec_viewer(const char *name, const char *page)
568 {
549 - const char *path = get_man_viewer_info(name);
569 + const char *info = get_man_viewer_info(name);
570
571 if (!strcasecmp(name, "man"))
552 - exec_man_man(path, page);
572 + exec_man_man(info, page);
573 else if (!strcasecmp(name, "woman"))
554 - exec_woman_emacs(path, page);
574 + exec_woman_emacs(info, page);
575 else if (!strcasecmp(name, "konqueror"))
556 - exec_man_konqueror(path, page);
576 + exec_man_konqueror(info, page);
577 + else if (info)
578 + exec_man_cmd(info, page);
579 else
558 - warning("'%s': unsupported man viewer.", name);
580 + warning("'%s': unknown man viewer.", name);
581 }
582
583 static void show_man_page(const char *git_cmd)