From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Zsh Users <zsh-users@zsh.org>
Cc: Bart Schaefer <schaefer@brasslantern.com>
Subject: Re: Alias call in function fails...
Date: Wed, 24 Jun 2020 10:47:12 +0000 [thread overview]
Message-ID: <20200624104712.48c4851f@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20200624101059.GB19280@tarpaulin.shahaf.local2>
Daniel Shahaf wrote on Wed, 24 Jun 2020 10:10 +0000:
> Bart Schaefer wrote on Tue, Jun 23, 2020 at 16:40:04 -0700:
> > On Tue, Jun 23, 2020 at 3:55 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > >
> > > I[...] it's perhaps not self-explanatory that nl(1) is an
> > > external command.
> >
> > You could use "cat -n" instead.
>
> It's unportable. I'd prefer a runnable example.
>
> How about:
Extended:
8<--8<--
From 4e1d6b29d42662eb9b6f5d1cf7dc3900c3142762 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Wed, 24 Jun 2020 10:40:23 +0000
Subject: [PATCH 1/2] Extend documentation of global aliases.
---
Doc/Zsh/builtins.yo | 8 +++++++-
Doc/Zsh/grammar.yo | 9 +++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index ada69c99a..d35cad182 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -105,7 +105,13 @@ For each var(name) with a corresponding var(value), define an alias
with that value. A trailing space in var(value) causes the next word
to be checked for alias expansion. If the tt(-g) flag is present,
define a global alias; global aliases are expanded even if they do not
-occur in command position.
+occur in command position:
+
+example(% perldoc --help 2>&1 | grep 'built-in functions'
+ -f Search Perl built-in functions
+% alias -g HG='--help 2>&1 | grep'
+% perldoc HG 'built-in functions'
+ -f Search Perl built-in functions)
If the tt(-s) flag is present, define a suffix alias: if the command
word on a command line is in the form `var(text)tt(.)var(name)', where
diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo
index a4e0c1121..7eabd75ce 100644
--- a/Doc/Zsh/grammar.yo
+++ b/Doc/Zsh/grammar.yo
@@ -597,6 +597,15 @@ word, e.g. tt(\foo). Any form of quoting works, although there is
nothing to prevent an alias being defined for the quoted form such as
tt(\foo) as well.
+In particular, note that quoting must be used when using tt(unalias) to remove
+global aliases:
+
+example(% alias -g foo=bar
+% unalias foo
+unalias: no such hash table element: bar
+% unalias \foo
+% )
+
When tt(POSIX_ALIASES) is set, only plain unquoted strings are eligible
for aliasing. The tt(alias) builtin does not reject ineligible aliases,
but they are not expanded.
From c554b79da628ea7eb96ff37ddaa456b07004bfe8 Mon Sep 17 00:00:00 2001
From: Daniel Shahaf <d.s@daniel.shahaf.name>
Date: Wed, 24 Jun 2020 10:40:45 +0000
Subject: [PATCH 2/2] Update aliases documentation for the addition of the
ALIAS_FUNC_DEF option.
---
Doc/Zsh/grammar.yo | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo
index 7eabd75ce..2eb2018d2 100644
--- a/Doc/Zsh/grammar.yo
+++ b/Doc/Zsh/grammar.yo
@@ -571,6 +571,11 @@ position (if it could be the first word of a simple command),
or if the alias is global.
If the replacement text ends with a space, the next word in the shell input
is always eligible for purposes of alias expansion.
+
+It is an error for the function name, var(word), in the sh-compatible function
+definition syntax `var(word) tt(+LPAR()+RPAR()) ...' to be a word that resulted
+from alias expansion, unless the tt(ALIAS_FUNC_DEF) option is set.
+
findex(alias, use of)
cindex(aliases, global)
An alias is defined using the tt(alias) builtin; global aliases
@@ -656,26 +661,6 @@ a problem in shell scripts, functions, and code executed with `tt(source)'
or `tt(.)'. Consequently, use of functions rather than aliases is
recommended in non-interactive code.
-Note also the unhelpful interaction of aliases and function definitions:
-
-example(alias func='noglob func'
-func+LPAR()RPAR() {
- echo Do something with $*
-})
-
-Because aliases are expanded in function definitions, this causes the
-following command to be executed:
-
-example(noglob func+LPAR()RPAR() {
- echo Do something with $*
-})
-
-which defines tt(noglob) as well as tt(func) as functions with the
-body given. To avoid this, either quote the name tt(func) or use the
-alternative function definition form `tt(function func)'. Ensuring the
-alias is defined after the function works but is problematic if the
-code fragment might be re-executed.
-
texinode(Quoting)()(Aliasing)(Shell Grammar)
sect(Quoting)
cindex(quoting)
next prev parent reply other threads:[~2020-06-24 10:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-22 12:49 Frank Gallacher
2020-06-22 23:23 ` Mikael Magnusson
2020-06-23 8:37 ` Andreas Kusalananda Kähäri
2020-06-23 9:14 ` Peter Stephenson
2020-06-23 9:55 ` Mikael Magnusson
2020-06-23 11:28 ` Andreas Kusalananda Kähäri
2020-06-23 12:04 ` Daniel Shahaf
2020-06-23 12:46 ` Perry Smith
2020-06-23 13:10 ` Kamil Dudka
2020-06-23 16:03 ` Bart Schaefer
2020-06-23 21:14 ` Perry Smith
2020-06-23 22:54 ` Daniel Shahaf
2020-06-23 23:29 ` Perry Smith
2020-06-23 23:43 ` Bart Schaefer
2020-06-24 0:47 ` Perry Smith
2020-06-24 9:28 ` Daniel Shahaf
2020-06-24 12:55 ` Perry Smith
2020-06-23 23:40 ` Bart Schaefer
2020-06-24 10:10 ` Daniel Shahaf
2020-06-24 10:47 ` Daniel Shahaf [this message]
2020-06-24 2:58 ` Grant Taylor
2020-06-29 16:24 ` Sebastian Gniazdowski
2020-06-29 16:55 ` Bart Schaefer
2020-06-30 4:02 ` Bart Schaefer
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=20200624104712.48c4851f@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=schaefer@brasslantern.com \
--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).