From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Lasse Makholm <lasse.makholm@gmail.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 14:32:01 -0400 [thread overview]
Message-ID: <20110322183201.GA22534@sigill.intra.peff.net> (raw)
In-Reply-To: <7vfwqfkphn.fsf@alter.siamese.dyndns.org>
On Tue, Mar 22, 2011 at 10:57:08AM -0700, Junio C Hamano wrote:
> The first addition is indeed a huge improvement.
>
> Note that any argument you pass when running aliases are simply
> appended to the shell command.
>
> The original didn't explicitly say it but it really should have. The
> example that comes before it, "alias.new = !...", should be updated with
> an invocation that takes a parameter, perhaps like this:
>
> With this alias defined:
>
> [alias] since = "!gitk --all --since"
>
> you can view commits in the last week with:
>
> $ git since 7.days
>
> because this expands to "gitk --all --since 7.days" by concatenating
> the arguments supplied at runtime to the alias.
>
> Then say that "Note ..." to stress that point. The description at that
> point has become much better.
>
> With that understanding already there,
>
> This means that "alias.foo = !echo $# args: $1, $2 and $3" will
> not do what you expect.
>
> is no longer true; nobody sane would expect that if you made them realize
> that "simply appended" already. Just dropping that sentence would make
> the resulting text flow much better.
Agreed, your version is better.
> If you want to refer to arguments given to the alias, you can
> wrap it as a shell script, e.g.
>
> [alias] reversed = "!sh -c 'echo $2 $1' -"
>
> or a shell function, e.g.
>
> [alias] reversed = "!reversed() { echo $2 $1 } && reversed"
>
> and invoke it like so:
>
> $ git reversed one two
> two one
>
> I personally think the former "sh -c <str> -" is the more traditional and
> well understood form (iow, an idiom) for people who breathe shells.
Yeah, that is probably true. One advantage of the function idiom is that
it doesn't happen inside single-quotes, so it's one less layer of
quoting to deal with. And of course it saves a shell invocation. So I
think mentioning both is reasonable.
> > +----------------------
> > +alias.foo = !echo $# args: $1, $2 and $3
> > +----------------------
>
> While I totally agree with the formatting advice you gave here, we may
> want to avoid this notation; neither "git config alias.foo = !echo ..."
> nor writing "alias.foo = ..." in .git/config file would work.
Yeah, I didn't even think about that, but you are right.
-Peff
next prev parent reply other threads:[~2011-03-22 18:32 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
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 [this message]
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=20110322183201.GA22534@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).