From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: what can be global aliases used for?
Date: Fri, 17 Feb 2023 18:15:40 +0100 [thread overview]
Message-ID: <CAN=4vMob+ZOiBYrCaNhPtbOa-AupAy7+BJdecoqu9grfOd_6kw@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVAX3oJdrJDiqjxsLMH5+DaYt09dwzqA01ZBEY3rWwd_5A@mail.gmail.com>
On Fri, Feb 17, 2023 at 3:59 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> I'm trying to get the suspected capabilities out of global aliases. Currently I'm using them for:
> - macro-like labels for exporting patterns like EMPTYSTR being [[:space:][:INVALID:]]# roughly, to a single place,
> - macro-like SNIP_EMULATE_OPTIONS_ZERO that invokes emulate, setopt and 0=...
>
> I wonder what else can global aliases do?
Global aliases are unhygienic macros. It's rarely a good idea to use
unhygienic macros in the code you share with others. If you must use
an unhygienic macro in shared code, give it a long and ugly name to
avoid clashes.
EMPTYSTR can be a parameter. You would have to use $~EMPTYSTR but
you'll avoid most of the pitfalls of unhygienic macros.
SNIP_EMULATE_OPTIONS_ZERO can also be a parameter, which you can use
via `eval $SNIP_EMULATE_OPTIONS_ZERO`. I do something like this in
zsh4humans:
typeset -gr _z4h_opt='emulate -L zsh &&
setopt typeset_silent pipe_fail extended_glob &&
setopt prompt_percent no_prompt_subst no_prompt_bang &&
setopt no_bg_nice no_aliases || return'
function foo() {
eval "$_z4h_opt"
# do stuff
}
function bar() {
eval "$_z4h_opt"
# do stuff
}
Roman.
next prev parent reply other threads:[~2023-02-17 17:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAKc7PVA0X1786JP7g69aDP8eL+1oAZpipVC-4BNm1KV=OPxe7A@mail.gmail.com>
2023-02-17 14:54 ` Sebastian Gniazdowski
2023-02-17 17:15 ` Roman Perepelitsa [this message]
2023-02-17 19:10 ` Bart Schaefer
2023-02-17 21:11 ` Lawrence Velázquez
2023-02-17 21:19 ` Roman Perepelitsa
2023-02-17 23:27 ` Lawrence Velázquez
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='CAN=4vMob+ZOiBYrCaNhPtbOa-AupAy7+BJdecoqu9grfOd_6kw@mail.gmail.com' \
--to=roman.perepelitsa@gmail.com \
--cc=sgniazdowski@gmail.com \
--cc=zsh-workers@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).