Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: make aliases work inside the function? (using a preprocessor?)
- X-seq: zsh-users 21514
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Marc Chantreux <khatar@xxxxxxxxx>
- Subject: Re: make aliases work inside the function? (using a preprocessor?)
- Date: Wed, 4 May 2016 10:21:44 -0700
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-transfer-encoding; bh=H8+C334zsI3DLyMLM5h63hJ4by58N5q/5ujNssmNwys=; b=vPNcRqFx8+d6yDz2xy4Nm8VkYDnsmV/bvChzHJdmRSlRS+7PgQoAdg3VOimYi72aeA aB91EGKbBSDt1Zfz6LJ0tLkeAbpIrSAv1fz9lHl4MI8gb+8eohYVgpwEpFJ93GR1MC7+ ZeO6q07C5/5exe+lRqtB6xU95bAAbtkYUJeAe0EYnCnc0A7VGvPIVwpM8K6j2F1vNAe4 ejk5Dhr/hEOZQlCd/mEVGQV4t6tOY56taeIZWV4iN4gbq7pvObgPXFzWNfsyBm5q34JY ag8jeO6tR6YWSe4EKxCE+VKGsZoyj8vIyTNowezNRy1F02aGJeERjaJX21zPBKrWb4DZ Aw5Q==
- In-reply-to: <20160504134632.GA5729@aurora-borealis.phear.org>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20160504134632.GA5729@aurora-borealis.phear.org>
In addition to what PWS and Oliver have said, it's possibly important
to point out that --
On Wed, May 4, 2016 at 6:46 AM, Marc Chantreux <khatar@xxxxxxxxx> wrote:
>
> % which €
> € () {
> setopt localoptions unset nowarncreateglobal
> "$@" }
-- aliases are never going to expand with the command word quoted as
in your "$@" substitution there. Oliver's suggestion would work, but
only because (as he mentioned) the alias would be expanded on the
interactive command line before the € function runs.
For this specific example, what you want is probably:
€ () {
setopt localoptions unset nowarncreateglobal
eval "$1" "${(q@)argv[2,-1]}"
}
The eval will expand aliases in $1 (the desired command word)
regardless of the order in which they are defined relative to the
function, and the (q@) assures that the rest of the arguments are
unmolested by eval.
Other uses of aliases need the approach outlined by Peter.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author