{"thread":{"id":"14474","subject":"Useful tip about !aliases","startedAt":"2008-07-16T00:46:08Z","lastAt":"2008-07-16T00:58:25Z","messageCount":3,"participants":["Kevin Ballard","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"83452","messageId":"3BD7F543-7CB4-48B6-8D2C-DEA2ADC6EF5F@sb.org","threadId":"14474","inReplyTo":null,"subject":"Useful tip about !aliases","fromName":"Kevin Ballard","fromEmail":"kevin@sb.org","sentAt":"2008-07-16T00:46:08Z","receivedAt":"2008-07-16T00:46:08Z","isPatch":false,"sender":{"key":"kevin@sb.org","avatar":"https://avatars.githubusercontent.com/u/714?v=4"},"body":"Here's something I discovered recently about !aliases that other folks  \nmight find useful. The canonical form for a shell alias is something  \nlike\n\n   git config alias.foo '!echo bar'\n\nwhere any args given to foo, as in `git foo blah` are passed along to  \nthe shell, so in this case `echo bar blah` would be invoked.\n\nSomething that I find very useful is the ability to interpolate  \narguments into the middle of a command. This doesn't seem possible at  \nfirst glance, not without a helper script. But it certainly is  \npossible, with the help of shell functions:\n\n   git config alias.reverse '!foo () { args=''; while [[ -n \"$*\" ]];  \ndo args=\"$1 $args\"; shift; done; echo $args; }; foo'\n\nNow if you invoke `git foo one two three` you'll get the response  \n\"three two one\".\n\nHere's another example. This one I particularly like. I call it 'send- \npatches', because what it does is it takes a single hash and creates  \npatches out of all commits since that hash, invokes send-mail on them,  \nand deletes them. It's a rather quick way of sending off patches. And  \nif you pass any extra arguments, they're given to git-send-email. The  \nmost useful part is it adjusts the patch prefix to contain the name of  \nthe repository itself, so your recipient knows exactly what your patch  \nis for.\n\n   git config --global alias.send-patches '!foo () { rev=\"$1\"; shift;  \ngit send-email $(git format-patch -o .mbox --no-prefix --subject- \nprefix=\"$(printf \"PATCH: %s\" $(basename $(cd \"$(git rev-parse --show- \ncdup)\" && pwd)))\" $rev) \"$@\"; rm -rf .mbox; }; foo'\n\n-Kevin Ballard\n\n-- \nKevin Ballard\nhttp://kevin.sb.org\nkevin@sb.org\nhttp://www.tildesoft.com\n"},{"id":"83454","messageId":"alpine.DEB.1.00.0807160250120.2841@eeepc-johanness","threadId":"14474","inReplyTo":"3BD7F543-7CB4-48B6-8D2C-DEA2ADC6EF5F@sb.org","subject":"Re: Useful tip about !aliases","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-07-16T00:50:48Z","receivedAt":"2008-07-16T00:50:48Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 15 Jul 2008, Kevin Ballard wrote:\n\n> Here's something I discovered recently about !aliases that other folks might\n> find useful. The canonical form for a shell alias is something like\n> \n>  git config alias.foo '!echo bar'\n> \n> where any args given to foo, as in `git foo blah` are passed along to the\n> shell, so in this case `echo bar blah` would be invoked.\n> \n> Something that I find very useful is the ability to interpolate arguments into\n> the middle of a command. This doesn't seem possible at first glance, not\n> without a helper script. But it certainly is possible, with the help of shell\n> functions:\n> \n>  git config alias.reverse '!foo () { args=''; while [[ -n \"$*\" ]]; do args=\"$1\n> $args\"; shift; done; echo $args; }; foo'\n\nOn the gitwiki, you will find a more elegant solution using \"sh -c\".\n\nCiao,\nDscho\n"},{"id":"83455","messageId":"EC8F3D14-CAD6-4337-B8AA-FD741E6313CE@sb.org","threadId":"14474","inReplyTo":"alpine.DEB.1.00.0807160250120.2841@eeepc-johanness","subject":"Re: Useful tip about !aliases","fromName":"Kevin Ballard","fromEmail":"kevin@sb.org","sentAt":"2008-07-16T00:58:25Z","receivedAt":"2008-07-16T00:58:25Z","isPatch":false,"sender":{"key":"kevin@sb.org","avatar":"https://avatars.githubusercontent.com/u/714?v=4"},"body":"On Jul 15, 2008, at 5:50 PM, Johannes Schindelin wrote:\n\n> Hi,\n>\n> On Tue, 15 Jul 2008, Kevin Ballard wrote:\n>\n>> Here's something I discovered recently about !aliases that other  \n>> folks might\n>> find useful. The canonical form for a shell alias is something like\n>>\n>> git config alias.foo '!echo bar'\n>>\n>> where any args given to foo, as in `git foo blah` are passed along  \n>> to the\n>> shell, so in this case `echo bar blah` would be invoked.\n>>\n>> Something that I find very useful is the ability to interpolate  \n>> arguments into\n>> the middle of a command. This doesn't seem possible at first  \n>> glance, not\n>> without a helper script. But it certainly is possible, with the  \n>> help of shell\n>> functions:\n>>\n>> git config alias.reverse '!foo () { args=''; while [[ -n \"$*\" ]];  \n>> do args=\"$1\n>> $args\"; shift; done; echo $args; }; foo'\n>\n> On the gitwiki, you will find a more elegant solution using \"sh -c\".\n\nI'd forgotten you can do that, but I disagree that it's more elegant.  \nIt's a bit shorter, certainly, but it also invokes another process.  \nUsing a shell function doesn't.\n\n-Kevin Ballard\n\n-- \nKevin Ballard\nhttp://kevin.sb.org\nkevin@sb.org\nhttp://www.tildesoft.com\n"}]}