zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Roman Neuhauser <neuhauser@sigpipe.cz>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: chpwd, precmd hooks have "zsh" in $0
Date: Sun, 15 Aug 2021 14:10:41 -0700	[thread overview]
Message-ID: <CAH+w=7YqACfc+QWMAxn4GhMOBzYQ3tcCPYD6Tyh=xToLEa+7_g@mail.gmail.com> (raw)
In-Reply-To: <YRSmIo0N4vu3zZ4h@isis.sigpipe.cz>

On Wed, Aug 11, 2021 at 9:40 PM Roman Neuhauser <neuhauser@sigpipe.cz> wrote:
>
> [...]  i want the
> shell to be simpler, conceptually smaller by having one kind of
> functions: those that have their name in $0 and which don't forget
> redirections defined after their body.

Just a couple of thoughts about the latter.

First, it doesn't work with autoload.  You end up having to do some
equivalent of adding the extra set of braces, inside the source file.

Second, just worth noting:

% func() { print $SECONDS } > /tmp/funcout
% setopt noclobber
% func
% func
zsh: file exists: /tmp/funcout
%

Third, I'm not convinced that the semantics of memoized redirections
in this way is actually simpler or easier for a user to understand.
It's the only case where you can write a redirection in (what appears
to be) a "simple command" (doc term) and NOT have it immediately take
effect.

Fourth, related, why is redirection different from pipelining in this
particular case?  Why not parse the entire pipeline as part of the
function definition?  (Which would have to be done by treating it as
part of the function Eprog, see $0 patch discussion on zsh-workers.)
The "workaround" for this one is to redirect to a command
substitution.

% function f2 { print $SECONDS } | cat -n
% f2
zsh: command not found: f2
% function f2 { print $SECONDS } >>(cat -n)
% f2
     1    186
%

I'll conclude by wondering if there are well-known semantics for
execution of what appears inside the command substitution in that last
example.  DO NOT TRY THIS:

% f3() { print $SECONDS } >>(f3)


      reply	other threads:[~2021-08-15 21:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 20:15 Roman Neuhauser
2021-08-09 21:26 ` Bart Schaefer
2021-08-10 11:33   ` Roman Neuhauser
2021-08-10 17:31     ` Bart Schaefer
2021-08-12  4:40       ` Roman Neuhauser
2021-08-15 21:10         ` Bart Schaefer [this message]

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='CAH+w=7YqACfc+QWMAxn4GhMOBzYQ3tcCPYD6Tyh=xToLEa+7_g@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=neuhauser@sigpipe.cz \
    --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).