Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: run-help: Support for svn and git

On Dec 30,  7:19pm, joerg@xxxxxxxxxxxx wrote:
} calling run-help for svn or git is often not very helpful.
} Would you include this change?

I don't think there's any reason to give git and/or svn any special
treatment that isn't applied to (say) cvs or apt or yum or ztcp or
zftp or any other command that uses "subcommands".

I also don't think it's the right approach to build special knowledge
into run-help of all possible commands that have subcommands.

If we're going to make a change for this it should be one that can
also be applied to "perl someprog.plx" or "sh yourscript.sh".

So, how about the below (which replaces the patch I sent in 243260).
This looks for a function (or alias or command) named "run-help-$1",
e.g. run-help-git or run-help-svn or run-help-perl or whatever.  If
one is found, it invokes that, otherwise it invokes "man" as always.

Then one can do:

    run-help-svn () {
      local cmd_args
      cmd_args=( ${@:#-*} )
      svn help $cmd_args[1]

And something similar for git.

Of course at this point we ought to add something to the manual (in the
contributions section, perhaps?) about the run-help function and its,
um, helpers.

Index: Functions/Misc/run-help
diff -c -r1.3 run-help
--- Functions/Misc/run-help	30 May 2007 03:36:56 -0000	1.3
+++ Functions/Misc/run-help	31 Dec 2007 02:51:44 -0000
@@ -85,7 +85,20 @@
 	man zshmisc
-	((! didman++)) && man $@
+        set -- $@:t
+	if ((! didman++))
+	then
+	    if whence -w "run-help-$1" >/dev/null
+	    then
+		local cmd_args
+		builtin getln cmd_args
+		builtin print -z "$cmd_args"
+		cmd_args=( ${${(z)cmd_args}[2,-1]} )
+		eval "run-help-$1 $cmd_args[@]"
+	    else
+		man $1
+	    fi
+	fi
     if ((i < $#places && ! didman))

Messages sorted by: Reverse Date, Date, Thread, Author