From: Lasse Makholm Date: Tue, 22 Mar 2011 13:35:10 GMT Subject: Re: Weird behavior of shell variables in git aliases Message-ID: In-Reply-To: <20110322132820.GA14559@sigill.intra.peff.net> On 22 March 2011 14:28, Jeff King wrote: > But I think that is a little too magic for my taste. Although the false > positives ("!echo 'literal $#'") and false negatives (you want "!foo" to > _ignore_ its parameters) are pretty obscure, I would prefer to keep > things simple. Then how about simply: diff --git a/Documentation/config.txt b/Documentation/config.txt index 6468a68..8097480 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -586,9 +586,16 @@ If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining "alias.new = !gitk --all --not ORIG_HEAD", the invocation "git new" is equivalent to running the shell command -"gitk --all --not ORIG_HEAD". Note that shell commands will be -executed from the top-level directory of a repository, which may -not necessarily be the current directory. +"gitk --all --not ORIG_HEAD". Note that any arguments you pass +when running aliases are simply appended to the shell command. +This means that "alias.foo = !echo $# args: $1, $2 and $3" will +not do what you expect. To use alias arguments as positional +parameters, wrap your command in a shell function: +"alias.foo = !foo () { echo $# args: $1, $2 and $3; }; foo" ++ +Shell commands will be executed from the top-level directory +of a repository, which may not necessarily be the current +directory. am.keepcr:: If true, git-am will call git-mailsplit for patches in mbox format -- /Lasse