git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Useful tip about !aliases

From
Kevin Ballard <kevin@sb.org>
Date
Jul 16, 2008, 00:58 UTC
Message-ID
<EC8F3D14-CAD6-4337-B8AA-FD741E6313CE@sb.org>
In-Reply-To
<alpine.DEB.1.00.0807160250120.2841@eeepc-johanness>
On Jul 15, 2008, at 5:50 PM, Johannes Schindelin wrote:
Show 27 quoted lines
> Hi,
>
> On Tue, 15 Jul 2008, Kevin Ballard wrote:
>
>> Here's something I discovered recently about !aliases that other  
>> folks might
>> find useful. The canonical form for a shell alias is something like
>>
>> git config alias.foo '!echo bar'
>>
>> where any args given to foo, as in `git foo blah` are passed along  
>> to the
>> shell, so in this case `echo bar blah` would be invoked.
>>
>> Something that I find very useful is the ability to interpolate  
>> arguments into
>> the middle of a command. This doesn't seem possible at first  
>> glance, not
>> without a helper script. But it certainly is possible, with the  
>> help of shell
>> functions:
>>
>> git config alias.reverse '!foo () { args=''; while [[ -n "$*" ]];  
>> do args="$1
>> $args"; shift; done; echo $args; }; foo'
>
> On the gitwiki, you will find a more elegant solution using "sh -c".

I'd forgotten you can do that, but I disagree that it's more elegant. It's a bit shorter, certainly, but it also invokes another process. Using a shell function doesn't.

-Kevin Ballard
-- 
Kevin Ballard
http://kevin.sb.org
kevin@sb.org
http://www.tildesoft.com
Previous: Johannes Schindelin
Message 3 of 3 in “Useful tip about !aliases”
  1. Kevin BallardJul 16, 2008
  2. Johannes SchindelinJul 16, 2008
  3. Kevin BallardJul 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.