Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: alias/anon_function quoting issue
- X-seq: zsh-users 29108
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: linuxtechguy@xxxxxxxxx
- Cc: zsh <zsh-users@xxxxxxx>
- Subject: Re: alias/anon_function quoting issue
- Date: Fri, 14 Jul 2023 09:42:00 -0700
- Archived-at: <https://zsh.org/users/29108>
- In-reply-to: <CA+rB6GJ_opAWNCCBbQC=KQLwvYpjJ2Z6SK+yNjXqpuYyfKN+aw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CA+rB6GJ_opAWNCCBbQC=KQLwvYpjJ2Z6SK+yNjXqpuYyfKN+aw@mail.gmail.com>
On Fri, Jul 14, 2023 at 7:47 AM Jim <linux.tech.guy@xxxxxxxxx> wrote:
>
> Note: This is not critical, just annoying that "I" can't figure it out.
Here's a little trick for making the shell figure it out for you.
Step 1: Define the function you want using a placeholder name of some sort:
function foo { Var=$'\e[' }
Step 2: Define the alias by referencing the $functions special
parameter (which contains only the body of each function):
alias foo="() { $functions[foo] }"
Step 3: Delete the placeholder function.
unfunction foo
Step 4 (if you want): Confirm the alias definition:
alias foo
The shell will use a bit more elaborate quoting than strictly
necessary in some cases (and for some reason $functions encodes the
body with a leading tab character, removing that if you want is left
as an exercise) but you shouldn't need to worry about it working.
I can't think of a reason to define a global alias as a function, but
be sure the placeholder name used at steps 1 and 3 is not a global
alias.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author