Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: chpwd, precmd hooks have "zsh" in $0



On Wed, Aug 11, 2021 at 9:40 PM Roman Neuhauser <neuhauser@xxxxxxxxxx> 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)




Messages sorted by: Reverse Date, Date, Thread, Author