From: Jeff King <peff@peff.net>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: Thiago Farina <tfransosi@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: git 'new' alias
Date: Mon, 5 Sep 2011 16:41:18 -0400 [thread overview]
Message-ID: <20110905204118.GA4221@sigill.intra.peff.net> (raw)
In-Reply-To: <vpqipp77xpb.fsf@bauges.imag.fr>
On Mon, Sep 05, 2011 at 06:36:48PM +0200, Matthieu Moy wrote:
> > $ git config alias.one
> > !f() { r=$1; shift; echo $r@{1}..$r@{0} "$@"; }; f
>
> (which, I've just discovered, should be written as
>
> [alias]
> one = "!f() { r=$1; shift; echo $r@{1}..$r@{0} "$@"; }; f"
>
> otherwise "git config" messes up with the ; in the line)
Yes, it definitely needs quotes. However, you also need to
backslash-escape the quotes inside, or you get:
$ git config alias.one
!f() { r=$1; shift; echo $r@{1}..$r@{0} $@; }; f
which will accidentally split any arguments with whitespace.
> I now have this, which is really ugly in a config file, but does the
> DWIMery I want:
>
> new = "!f () { if echo \"$1\" | grep -q -e '^-' -e '^$'; then r=; else r=$1; shift; fi; git log $r@{1}..$r@{0} \"$@\"; } && f"
Instead of piping into grep, I would do:
case "$1" in
""|-*) ;;
*) r=$1; shift ;;
esac
which saves a process (and is IMHO a little more obvious).
As far as getting ugly for a config file, I would note that:
1. You can always drop a git-new script in your PATH. :)
2. You can backslash-escape literal newlines in config entries. It's
not amazingly pretty, but it can help:
[alias]
new = "! \
f() { \
case \"$1\" in \
''|-*) ;; \
*) r=$1; shift ;; \
esac; \
git log $r@{1}..$r@{0} \"$@\"; \
}; \
f"
-Peff
PS I use a similar alias, and I have found that defaulting to "--oneline
--graph --boundary $r@{0}...@r{1}" is quite nice for seeing how you
differ from upstream.
prev parent reply other threads:[~2011-09-05 20:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-01 19:30 git 'new' alias Thiago Farina
2011-09-01 19:40 ` Matthieu Moy
2011-09-01 21:17 ` Jeff King
2011-09-05 16:36 ` Matthieu Moy
2011-09-05 20:41 ` Jeff King [this message]
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=20110905204118.GA4221@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=git@vger.kernel.org \
--cc=tfransosi@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).