3 ms·
Seems it's to allow implicit and explicit use of arguments passed to alias. Git does the following to the alias string[1]: argv_array_pushf(out, "%s \"$@\"",
by jolmg 6y ago
Seems it's to allow implicit and explicit use of arguments passed to alias. Git does the following to the alias string[1]:
argv_array_pushf(out, "%s \"$@\"", argv[0]);
So, you can have aliases like `!grep foobar` to automatically accept arguments or aliases like yours that use arguments explicitly.
I've done aliases like `!bash -c 'foo $1' sh` before, but on seeing yours, I see that it was unnecessary to re-wrap with bash.
[1] https://github.com/git/git/blob/e31aba42fb12bdeb0f850829e008e1e3f43af500/run-command.c#L286 https://github.com/git/git/blob/e31aba42fb12bdeb0f850829e008...
- varl 6y agoInteresting! Thanks for digging up the code.
- lilyball 6y agoHuh I had no idea $1/$2/etc worked as-is in an alias. The advice I learned years ago for dealing with any alias that needs to do something custom with parameters is to write it like git config alias.foo '!f() { actual command goes here }; f' as that will pass all the args to the shell function. But if git is already setting it up so the args work then suffixing the alias with ";:" seems simpler.
- jolmg 6y ago> The advice I learned years ago Being able to use $1/$2/etc directly might be a relatively new development. EDIT: Or maybe not. This might have been doable since 2010: https://github.com/git/git/commit/8dba1e634af1d973a47fca616a63e7062a256790 https://github.com/git/git/commit/8dba1e634af1d973a47fca616a...
- lilyball 6y ago2010 is still “new development” to me