{"thread":{"id":"13253","subject":"[PATCH 3/5] help: use \"man.<tool>.cmd\" as custom man viewer command","startedAt":"2008-04-25T06:24:58Z","lastAt":"2008-04-25T06:24:58Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"75169","messageId":"20080425082458.bfc113ac.chriscool@tuxfamily.org","threadId":"13253","inReplyTo":null,"subject":"[PATCH 3/5] help: use \"man.<tool>.cmd\" as custom man viewer command","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-04-25T06:24:58Z","receivedAt":"2008-04-25T06:24:58Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Currently \"git help -m GITCMD\" is restricted to a set of man viewers\ndefined at compile time. You can subvert the \"man.<tool>.path\" to\nforce \"git help -m\" to use a different man, viewer, but if you have a\nman viewer whose invocation syntax does not match one of the current\ntools then you would have to write a wrapper script for it.\n\nThis patch adds a git config variable \"man.<tool>.cmd\" which allows a\nmore flexible man viewer choice.\n\nIf you run \"git help -m GITCMD\" with the \"man.viewer\" config variable\nset to an unrecognized tool then it will query the \"man.<tool>.cmd\"\nconfig variable. If this variable exists, then the specified tool will\nbe treated as a custom man viewer and it will be run in a shell with\nthe man page name of the GITCMD added as extra parameter.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n help.c |   58 ++++++++++++++++++++++++++++++++++++++++------------------\n 1 files changed, 40 insertions(+), 18 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 7373aa2..eb13e9a 100644\n--- a/help.c\n+++ b/help.c\n@@ -160,7 +160,15 @@ static void exec_man_man(const char* path, const char *page)\n \twarning(\"failed to exec '%s': %s\", path, strerror(errno));\n }\n \n-static void do_add_man_viewer(const char *name)\n+static void exec_man_cmd(const char *cmd, const char *page)\n+{\n+\tstruct strbuf shell_cmd = STRBUF_INIT;\n+\tstrbuf_addf(&shell_cmd, \"%s %s\", cmd, page);\n+\texecl(\"/bin/sh\", \"sh\", \"-c\", shell_cmd.buf, NULL);\n+\twarning(\"failed to exec '%s': %s\", cmd, strerror(errno));\n+}\n+\n+static void add_man_viewer(const char *name)\n {\n \tstruct man_viewer_list **p = &man_viewer_list;\n \tsize_t len = strlen(name);\n@@ -178,16 +186,6 @@ static int supported_man_viewer(const char *name, size_t len)\n \t\t!strncasecmp(\"konqueror\", name, len));\n }\n \n-static int add_man_viewer(const char *value)\n-{\n-\tif (supported_man_viewer(value, strlen(value)))\n-\t\tdo_add_man_viewer(value);\n-\telse\n-\t\twarning(\"'%s': unsupported man viewer.\", value);\n-\n-\treturn 0;\n-}\n-\n static void do_add_man_viewer_info(const char *name,\n \t\t\t\t   size_t len,\n \t\t\t\t   const char *value)\n@@ -207,7 +205,23 @@ static int add_man_viewer_path(const char *name,\n \tif (supported_man_viewer(name, len))\n \t\tdo_add_man_viewer_info(name, len, value);\n \telse\n-\t\twarning(\"'%s': path for unsupported man viewer.\", name);\n+\t\twarning(\"'%s': path for unsupported man viewer.\\n\"\n+\t\t\t\"Please consider using 'man.<tool>.cmd' instead.\",\n+\t\t\tname);\n+\n+\treturn 0;\n+}\n+\n+static int add_man_viewer_cmd(const char *name,\n+\t\t\t      size_t len,\n+\t\t\t      const char *value)\n+{\n+\tif (supported_man_viewer(name, len))\n+\t\twarning(\"'%s': cmd for supported man viewer.\\n\"\n+\t\t\t\"Please consider using 'man.<tool>.path' instead.\",\n+\t\t\tname);\n+\telse\n+\t\tdo_add_man_viewer_info(name, len, value);\n \n \treturn 0;\n }\n@@ -225,6 +239,11 @@ static int add_man_viewer_info(const char *var, const char *value)\n \t\t\treturn config_error_nonbool(var);\n \t\treturn add_man_viewer_path(name, subkey - name, value);\n \t}\n+\tif (!strcmp(subkey, \".cmd\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\treturn add_man_viewer_cmd(name, subkey - name, value);\n+\t}\n \n \twarning(\"'%s': unsupported man viewer sub key.\", subkey);\n \treturn 0;\n@@ -241,7 +260,8 @@ static int git_help_config(const char *var, const char *value)\n \tif (!strcmp(var, \"man.viewer\")) {\n \t\tif (!value)\n \t\t\treturn config_error_nonbool(var);\n-\t\treturn add_man_viewer(value);\n+\t\tadd_man_viewer(value);\n+\t\treturn 0;\n \t}\n \tif (!prefixcmp(var, \"man.\"))\n \t\treturn add_man_viewer_info(var, value);\n@@ -543,16 +563,18 @@ static void setup_man_path(void)\n \n static void exec_viewer(const char *name, const char *page)\n {\n-\tconst char *path = get_man_viewer_info(name);\n+\tconst char *info = get_man_viewer_info(name);\n \n \tif (!strcasecmp(name, \"man\"))\n-\t\texec_man_man(path, page);\n+\t\texec_man_man(info, page);\n \telse if (!strcasecmp(name, \"woman\"))\n-\t\texec_woman_emacs(path, page);\n+\t\texec_woman_emacs(info, page);\n \telse if (!strcasecmp(name, \"konqueror\"))\n-\t\texec_man_konqueror(path, page);\n+\t\texec_man_konqueror(info, page);\n+\telse if (info)\n+\t\texec_man_cmd(info, page);\n \telse\n-\t\twarning(\"'%s': unsupported man viewer.\", name);\n+\t\twarning(\"'%s': unknown man viewer.\", name);\n }\n \n static void show_man_page(const char *git_cmd)\n-- \n1.5.5.130.g3ab1e.dirty\n"}]}