From: Bart Schaefer <schaefer@brasslantern.com>
To: Marc Chantreux <khatar@phear.org>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: make aliases work inside the function? (using a preprocessor?)
Date: Wed, 4 May 2016 10:21:44 -0700 [thread overview]
Message-ID: <CAH+w=7bcZbDtS_c_B61LvYD=zdUMm2BMAxdkPCKs7RybO7OG4Q@mail.gmail.com> (raw)
In-Reply-To: <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@phear.org> 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.
next prev parent reply other threads:[~2016-05-04 17:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-04 13:46 Marc Chantreux
2016-05-04 14:04 ` Peter Stephenson
2016-05-04 14:55 ` Oliver Kiddle
2016-05-04 17:21 ` Bart Schaefer [this message]
2016-05-09 12:30 ` Marc Chantreux
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='CAH+w=7bcZbDtS_c_B61LvYD=zdUMm2BMAxdkPCKs7RybO7OG4Q@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=khatar@phear.org \
--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).