From: Jeff King <peff@peff.net>
To: Lasse Makholm <lasse.makholm@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Erik Faye-Lund <kusmabite@gmail.com>,
Dun Peal <dunpealer@gmail.com>,
git@vger.kernel.org
Subject: Re: Weird behavior of shell variables in git aliases
Date: Tue, 22 Mar 2011 09:43:58 -0400 [thread overview]
Message-ID: <20110322134358.GA19064@sigill.intra.peff.net> (raw)
In-Reply-To: <AANLkTin3fXkGaC5cTVny5adU=FusQV0WAcPHLUEeEzLi@mail.gmail.com>
On Tue, Mar 22, 2011 at 02:35:10PM +0100, Lasse Makholm wrote:
> On 22 March 2011 14:28, Jeff King <peff@peff.net> 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.
Yeah, that certainly improves the situation.
A small formatting nit: Those long commands with punctuation get hard to
read in the middle of a paragraph. Maybe something like this on top:
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3916665..d2b7515 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -582,10 +582,18 @@ it will be treated as a shell command. For example, defining
"git new" is equivalent to running the shell command
"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
+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"
++
+----------------------
+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
-Peff
PS Your patch was wrapped on the @@ line. You might want to check your
mailer settings.
next prev parent reply other threads:[~2011-03-22 13:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-21 16:39 Weird behavior of shell variables in git aliases Dun Peal
2011-03-21 21:53 ` Jeff King
2011-03-21 22:21 ` Junio C Hamano
2011-03-21 22:33 ` Junio C Hamano
2011-03-22 10:38 ` Lasse Makholm
2011-03-22 11:28 ` Jeff King
2011-03-22 12:59 ` Lasse Makholm
2011-03-22 10:52 ` Ævar Arnfjörð Bjarmason
2011-03-22 11:18 ` Jeff King
2011-03-22 13:28 ` Jeff King
2011-03-22 13:35 ` Lasse Makholm
2011-03-22 13:43 ` Jeff King [this message]
2011-03-22 13:53 ` Lasse Makholm
2011-03-22 15:06 ` Dun Peal
2011-03-22 17:57 ` Junio C Hamano
2011-03-22 18:32 ` Jeff King
2011-03-22 22:22 ` Lasse Makholm
2011-03-23 3:01 ` Junio C Hamano
2011-03-22 17:36 ` Junio C Hamano
2011-03-22 17:35 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110322134358.GA19064@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=dunpealer@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kusmabite@gmail.com \
--cc=lasse.makholm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).