{"thread":{"id":"8796","subject":"[PATCH] Make '!' aliases more useful","startedAt":"2007-07-01T21:51:58Z","lastAt":"2007-07-03T12:10:18Z","messageCount":11,"participants":["Johannes Schindelin","Theodore Tso","Junio C Hamano","Alex Riesen","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"46196","messageId":"Pine.LNX.4.64.0707012249590.4438@racer.site","threadId":"8796","inReplyTo":null,"subject":"[PATCH] Make '!' aliases more useful","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-01T21:51:58Z","receivedAt":"2007-07-01T21:51:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWhen an alias starts with an exclamation mark, the rest is interpreted\nas a shell command. However, all arguments passed to git used to be\nignored.\n\nNow you can have an alias like\n\n\t$ git config alias.e '!echo'\n\nand\n\n\t$ git e Hello World\n\ndoes what you expect it to do.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tI have this in my $HOME/.gitconfig:\n\n\t\t[alias]\n\t\t\tdebug = !GIT_PAGER= gdb --args git\n\n\twhich allows me to debug, say \"git log a..b\" by saying \"git debug \n\tlog a..b\".\n\n git.c |   15 +++++++++++++++\n 1 files changed, 15 insertions(+), 0 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 8ea70da..32e8aa9 100644\n--- a/git.c\n+++ b/git.c\n@@ -205,6 +205,21 @@ static int handle_alias(int *argcp, const char ***argv)\n \tgit_config(git_alias_config);\n \tif (alias_string) {\n \t\tif (alias_string[0] == '!') {\n+\t\t\tif (*argcp > 1) {\n+\t\t\t\tint i, sz = PATH_MAX;\n+\t\t\t\tchar *s = xmalloc(sz), *new_alias = s;\n+\n+\t\t\t\tadd_to_string(&s, &sz, alias_string, 0);\n+\t\t\t\tfree(alias_string);\n+\t\t\t\talias_string = new_alias;\n+\t\t\t\tfor (i = 1; i < *argcp &&\n+\t\t\t\t\t!add_to_string(&s, &sz, \" \", 0) &&\n+\t\t\t\t\t!add_to_string(&s, &sz, (*argv)[i], 1)\n+\t\t\t\t\t; i++)\n+\t\t\t\t\t; /* do nothing */\n+\t\t\t\tif (!sz)\n+\t\t\t\t\tdie(\"Too many or long arguments\");\n+\t\t\t}\n \t\t\ttrace_printf(\"trace: alias to shell cmd: %s => %s\\n\",\n \t\t\t\t     alias_command, alias_string + 1);\n \t\t\tret = system(alias_string + 1);\n-- \n1.5.2.2.3276.gf2524-dirty\n"},{"id":"46245","messageId":"20070702145549.GB4720@thunk.org","threadId":"8796","inReplyTo":"Pine.LNX.4.64.0707012249590.4438@racer.site","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Theodore Tso","fromEmail":"tytso@mit.edu","sentAt":"2007-07-02T14:55:49Z","receivedAt":"2007-07-02T14:55:49Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"On Sun, Jul 01, 2007 at 10:51:58PM +0100, Johannes Schindelin wrote:\n> \n> When an alias starts with an exclamation mark, the rest is interpreted\n> as a shell command. However, all arguments passed to git used to be\n> ignored.\n> \n> Now you can have an alias like\n> \n> \t$ git config alias.e '!echo'\n> \n> and\n> \n> \t$ git e Hello World\n> \n> does what you expect it to do.\n\nBut what if you don't want the argument passed at the end of the\nalias, but somewhere else?  I suspect the better answer would be to\nsupport $* and $1, $2, $3, et. al interpolation, no?  It was on my\nlist of things to do when I had a spare moment, but I never got around\nto it.\n\n\t\t\t\t\t- Ted\n"},{"id":"46249","messageId":"Pine.LNX.4.64.0707021654450.4071@racer.site","threadId":"8796","inReplyTo":"20070702145549.GB4720@thunk.org","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-02T15:55:24Z","receivedAt":"2007-07-02T15:55:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 2 Jul 2007, Theodore Tso wrote:\n\n> On Sun, Jul 01, 2007 at 10:51:58PM +0100, Johannes Schindelin wrote:\n> > \n> > When an alias starts with an exclamation mark, the rest is interpreted\n> > as a shell command. However, all arguments passed to git used to be\n> > ignored.\n> > \n> > Now you can have an alias like\n> > \n> > \t$ git config alias.e '!echo'\n> > \n> > and\n> > \n> > \t$ git e Hello World\n> > \n> > does what you expect it to do.\n> \n> But what if you don't want the argument passed at the end of the\n> alias, but somewhere else?  I suspect the better answer would be to\n> support $* and $1, $2, $3, et. al interpolation, no?  It was on my\n> list of things to do when I had a spare moment, but I never got around\n> to it.\n\nThere is a point where you do not want to complicate git, but rather write \na script. This is such a point IMHO.\n\nCiao,\nDscho\n"},{"id":"46250","messageId":"20070702160810.GD4720@thunk.org","threadId":"8796","inReplyTo":"Pine.LNX.4.64.0707021654450.4071@racer.site","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Theodore Tso","fromEmail":"tytso@mit.edu","sentAt":"2007-07-02T16:08:10Z","receivedAt":"2007-07-02T16:08:10Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:\n> > But what if you don't want the argument passed at the end of the\n> > alias, but somewhere else?  I suspect the better answer would be to\n> > support $* and $1, $2, $3, et. al interpolation, no?  It was on my\n> > list of things to do when I had a spare moment, but I never got around\n> > to it.\n> \n> There is a point where you do not want to complicate git, but rather write \n> a script. This is such a point IMHO.\n\nSuch a point exists, I agree, but I would draw after $* and $1/$2/$3\ninterpolation.  There is a lot more value that gets added with\npositional arguments support, and it makes git aliases more usable on\nplatforms such as Windows where scripting capability is much more\nlimited.\n\nRegards,\n\n\t\t\t\t\t- Ted\n"},{"id":"46295","messageId":"7vr6nqwgdi.fsf@assigned-by-dhcp.cox.net","threadId":"8796","inReplyTo":"20070702160810.GD4720@thunk.org","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-02T23:11:21Z","receivedAt":"2007-07-02T23:11:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Theodore Tso <tytso@mit.edu> writes:\n\n> On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:\n>> > But what if you don't want the argument passed at the end of the\n>> > alias, but somewhere else?  I suspect the better answer would be to\n>> > support $* and $1, $2, $3, et. al interpolation, no?  It was on my\n>> > list of things to do when I had a spare moment, but I never got around\n>> > to it.\n>> \n>> There is a point where you do not want to complicate git, but rather write \n>> a script. This is such a point IMHO.\n>\n> Such a point exists, I agree, but I would draw after $* and $1/$2/$3\n> interpolation.  There is a lot more value that gets added with\n> positional arguments support, and it makes git aliases more usable on\n> platforms such as Windows where scripting capability is much more\n> limited.\n\nThat actually sounds sensible, but you could alias\n\n\t!sh -c 'command $2 $1 $3'\n\nto reorder the parameters, couldn't you?\n\t\n"},{"id":"46310","messageId":"20070703011429.GB5322@thunk.org","threadId":"8796","inReplyTo":"7vr6nqwgdi.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Theodore Tso","fromEmail":"tytso@mit.edu","sentAt":"2007-07-03T01:14:29Z","receivedAt":"2007-07-03T01:14:29Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"On Mon, Jul 02, 2007 at 04:11:21PM -0700, Junio C Hamano wrote:\n> > Such a point exists, I agree, but I would draw after $* and $1/$2/$3\n> > interpolation.  There is a lot more value that gets added with\n> > positional arguments support, and it makes git aliases more usable on\n> > platforms such as Windows where scripting capability is much more\n> > limited.\n> \n> That actually sounds sensible, but you could alias\n> \n> \t!sh -c 'command $2 $1 $3'\n> \n> to reorder the parameters, couldn't you?\n\nUm, how would that work on the Windows platform?\n\n(I'm assuming here that we are trying to support Windows better, since\nthere are projects such as Mozilla, and MySQL that care very much\nabout first class Windows support.  We could say this isn't important\nenough, and that would be fine; but I wanted to at least raise the\nquestion.)\n\n\t\t\t\t\t\t- Ted\n"},{"id":"46311","messageId":"Pine.LNX.4.64.0707030220460.4071@racer.site","threadId":"8796","inReplyTo":"20070703011429.GB5322@thunk.org","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-03T01:37:43Z","receivedAt":"2007-07-03T01:37:43Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 2 Jul 2007, Theodore Tso wrote:\n\n> On Mon, Jul 02, 2007 at 04:11:21PM -0700, Junio C Hamano wrote:\n> > > Such a point exists, I agree, but I would draw after $* and $1/$2/$3\n> > > interpolation.  There is a lot more value that gets added with\n> > > positional arguments support, and it makes git aliases more usable on\n> > > platforms such as Windows where scripting capability is much more\n> > > limited.\n> > \n> > That actually sounds sensible, but you could alias\n> > \n> > \t!sh -c 'command $2 $1 $3'\n> > \n> > to reorder the parameters, couldn't you?\n> \n> Um, how would that work on the Windows platform?\n> \n> (I'm assuming here that we are trying to support Windows better, since\n> there are projects such as Mozilla, and MySQL that care very much\n> about first class Windows support.  We could say this isn't important\n> enough, and that would be fine; but I wanted to at least raise the\n> question.)\n\nWindows support for those people unwilling to use cygwin amounts to \nanything, but a command line interface. Since aliases are _bound_ to \nthe command line, I do not really get your point here.\n\nIn my view of things, for Windows support it is first of all important to \nget rid of the dependency on bash in the core parts. Then we should \ncontinue on the work Han-Wen did with his gub, and produce a proper \nWindows-clicky-style installer which installs git-gui with a proper \nWindows Start Menu item. But of course, then we should brace ourselves for \na lot of clueless^Winterested users.\n\nCiao,\nDscho\n"},{"id":"46336","messageId":"81b0412b0707030007o328f0b35hfa758e1f3b2ef289@mail.gmail.com","threadId":"8796","inReplyTo":"20070702160810.GD4720@thunk.org","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-07-03T07:07:10Z","receivedAt":"2007-07-03T07:07:10Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 7/2/07, Theodore Tso <tytso@mit.edu> wrote:\n> On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:\n> > > But what if you don't want the argument passed at the end of the\n> > > alias, but somewhere else?  I suspect the better answer would be to\n> > > support $* and $1, $2, $3, et. al interpolation, no?  It was on my\n> > > list of things to do when I had a spare moment, but I never got around\n> > > to it.\n> >\n> > There is a point where you do not want to complicate git, but rather write\n> > a script. This is such a point IMHO.\n>\n> Such a point exists, I agree, but I would draw after $* and $1/$2/$3\n> interpolation.  There is a lot more value that gets added with\n> positional arguments support, and it makes git aliases more usable on\n> platforms such as Windows where scripting capability is much more\n> limited.\n\nI don't think it is _possible_ to make it work on Windows properly: you have\nto quote the arguments with whitespaces as there is nothing like argv there\n(windows programs don't use command line, so it does not exist).\nAs the quoting is implemented in the programs the rules are all different\nand mostly suboptimal.\n"},{"id":"46337","messageId":"4689F9CB.ED2A2848@eudaptics.com","threadId":"8796","inReplyTo":"20070703011429.GB5322@thunk.org","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-07-03T07:24:59Z","receivedAt":"2007-07-03T07:24:59Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Theodore Tso wrote:\n> \n> On Mon, Jul 02, 2007 at 04:11:21PM -0700, Junio C Hamano wrote:\n> > > Such a point exists, I agree, but I would draw after $* and $1/$2/$3\n> > > interpolation.  There is a lot more value that gets added with\n> > > positional arguments support, and it makes git aliases more usable on\n> > > platforms such as Windows where scripting capability is much more\n> > > limited.\n> >\n> > That actually sounds sensible, but you could alias\n> >\n> >       !sh -c 'command $2 $1 $3'\n> >\n> > to reorder the parameters, couldn't you?\n> \n> Um, how would that work on the Windows platform?\n\nShouldn't be a problem for Cygwin users, nor for MinGW port users. The\nlatter need a Bourne shell anyway for the various scripted git tools.\n\n-- Hannes\n"},{"id":"46347","messageId":"Pine.LNX.4.64.0707031217480.4071@racer.site","threadId":"8796","inReplyTo":"81b0412b0707030007o328f0b35hfa758e1f3b2ef289@mail.gmail.com","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-03T11:27:35Z","receivedAt":"2007-07-03T11:27:35Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 3 Jul 2007, Alex Riesen wrote:\n\n> On 7/2/07, Theodore Tso <tytso@mit.edu> wrote:\n> > On Mon, Jul 02, 2007 at 04:55:24PM +0100, Johannes Schindelin wrote:\n> > > > But what if you don't want the argument passed at the end of the\n> > > > alias, but somewhere else?  I suspect the better answer would be to\n> > > > support $* and $1, $2, $3, et. al interpolation, no?  It was on my\n> > > > list of things to do when I had a spare moment, but I never got around\n> > > > to it.\n> > >\n> > > There is a point where you do not want to complicate git, but rather\n> > write\n> > > a script. This is such a point IMHO.\n> > \n> > Such a point exists, I agree, but I would draw after $* and $1/$2/$3\n> > interpolation.  There is a lot more value that gets added with\n> > positional arguments support, and it makes git aliases more usable on\n> > platforms such as Windows where scripting capability is much more\n> > limited.\n> \n> I don't think it is _possible_ to make it work on Windows properly: you have\n> to quote the arguments with whitespaces as there is nothing like argv there\n> (windows programs don't use command line, so it does not exist).\n\nSince the \"!\" aliases use system() (i.e. no argv, but a plain string as \nparameter), my patch already does that. It quotes the arguments properly.\n\n> As the quoting is implemented in the programs the rules are all different\n> and mostly suboptimal.\n\nYou mean the programs that could be called via \"!\" aliases? Yes, that is \nright. And there is also the problem that you have to convert path names \nif you are working on Windows, because of this c:\\&@!§$ braindamage.\n\nHowever, in this case Junio's idea to use the shell to do the hard work is \nagain an alternative:\n\n\t[alias]\n\t\talex = !sh -c 'd:\\program.exe $(cygpath -w \"$1\")'\n\nFWIW I do not think that executing the shell from time to time is a big \nproblem. It's only that I would like to get rid of the dependency on perl \nand bash for the plain Windows user, who will not dare to leave the gui \ninto the command line jungle where there be bisons, yaccs and kills.\n\nCiao,\nDscho\n"},{"id":"46354","messageId":"20070703121018.GD5322@thunk.org","threadId":"8796","inReplyTo":"Pine.LNX.4.64.0707030220460.4071@racer.site","subject":"Re: [PATCH] Make '!' aliases more useful","fromName":"Theodore Tso","fromEmail":"tytso@mit.edu","sentAt":"2007-07-03T12:10:18Z","receivedAt":"2007-07-03T12:10:18Z","isPatch":true,"sender":{"key":"tytso@mit.edu","avatar":"https://avatars.githubusercontent.com/u/51416?v=4"},"body":"On Tue, Jul 03, 2007 at 02:37:43AM +0100, Johannes Schindelin wrote:\n> Windows support for those people unwilling to use cygwin amounts to \n> anything, but a command line interface. Since aliases are _bound_ to \n> the command line, I do not really get your point here.\n\nYou're right of course.  <small>Never mind...</small>\n\n\t\t\t\t\t\t- Ted\n"}]}