Re: git 'new' alias

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]