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

Re: make aliases work inside the function? (using a preprocessor?)

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