To run commands inside a git alias and, in particular, pass arguments to these commands, you probably have to create a temporary function that you call immediately:
$ vim ~/.gitconfig ... [alias] # compare: foo = "! echo begin arg=$1/$2/end" foo2 = "!f() { echo "begin arg=$1/$2/end"; }; f"
In this example, you probably need a function (and also more flexible as to what you can do in one βstatementβ); and you can probably say that for both options the rest of the git command arguments are simply passed as args for the alias, whether it is "echo" or "f"; the function call simply absorbs the arguments, ignoring what is not explicitly used:
$ git foo abc begin arg=a/b/end abc $ git foo2 abc begin arg=a/b/end
Another example (all aliases based on the matching pattern are listed) (note: you can reuse the same function name "f ()" in the .gitconfig file):
[alias] alias = "!f() { git config --get-regexp "^alias.${1}$" ; }; f"
The first returns an alias only for "foo $", the second for "foo. *":
$ git alias foo alias.foo ! echo begin arg=$1/$2/end $ git alias 'foo.*' alias.foo ! echo begin arg=$1/$2/end alias.foo2 !f() { echo begin arg=$1/$2/end; }; f
(nb: actual results may vary by shell, I use this with bash on Linux, Unix, and Cygwin (Windows).)
michael Feb 21 '13 at 5:04 on 2013-02-21 05:04
source share