Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: what can be global aliases used for?
On Fri, Feb 17, 2023 at 3:59 PM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author