zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: Multi-word aliases?
Date: Tue, 04 Nov 2014 11:32:19 +0000	[thread overview]
Message-ID: <20141104113219.03a4a527@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20141104104339.GA6255@linux.vnet.ibm.com>

On Tue, 04 Nov 2014 11:43:39 +0100
Dominik Vogt <vogt@linux.vnet.ibm.com> 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)
  fi

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).

pws


  parent reply	other threads:[~2014-11-04 11:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04  9:08 Dominik Vogt
2014-11-04  9:56 ` Peter Stephenson
2014-11-04 10:43   ` Dominik Vogt
2014-11-04 10:59     ` Mikael Magnusson
2014-11-04 11:33       ` Dominik Vogt
2014-11-04 12:32         ` Mikael Magnusson
2014-11-04 12:39           ` Peter Stephenson
2014-11-04 12:53             ` Dominik Vogt
2014-11-04 15:57               ` Vincent Lefevre
2014-11-04 11:32     ` Peter Stephenson [this message]
     [not found] <20141104090838.GA27526__23771.1416128606$1415092256$gmane$org@linux.vnet.ibm.com>
2014-11-04 10:20 ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141104113219.03a4a527@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).