Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Multi-word aliases?

On Tue, 04 Nov 2014 11:43:39 +0100
Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> Just to better understand the situation, is there any technical
> reason to limit the scope of aliases to the first word of the
> command line?  After all, zsh already has to look everywhere for
> global aliases.

Yes, the space triggers the expansion.  Then the resulting token is
passed up to the lexical analyser.  There's no obvious way of having it
expand multi-word aliases without it not being able to parse token by
token. This rather destroys the shell's ability to parse at all.

> Btw., there's no simple way to do regexp search and replace on
> command lines like
>   s/^(git\w.*\wrebase\w)(.*)/\1 --keep-empty\2/
> or is there? (\w is an ad-hoc expression for a token boundary)

I'm not sure if you mean "on a command line passed to a script" or "on a
command line I'm editing".  In context, I'm assuming the former.  In
that case you can do stuff like

  integer index=${argv[(I)rebase]}
  if (( index )); then
    argv[index]=(rebase --keep-empty)

The way I've done it it's been careful about keeping command line
elements separate; there's no problem with word-splitting.

Tested, for once.  You could do that in a git wrapper, but you still
have the problem that the "rebase" could be some later argument
along the command line (or even an argument to a global option).


Messages sorted by: Reverse Date, Date, Thread, Author