From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29680 invoked from network); 10 Aug 2021 11:34:36 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Aug 2021 11:34:36 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1628595276; b=mkwLrNg5sdw7lGhYnr3jFx6Cvj7GZnOHxbmeGtM3ta7W6ExdLFtv7KdCLypEP9WREdJHbmH7Ks HWNsDKwa5cpsLJGal5AcN3eGAz1cXVvVDuzwq02G1UqZqB03Ap5WVdWPOK/tFyI6IVdnBrVQf/ s6jT2urF2fkbsp0JQ0i1Mes+ufN07dkaeQ9YP82sj1CNhun0rAvzDtqRUjAdGjJxnYfO07OAhs WUnE5lvgC5SVlKYzlbEzIYGpUViAsxdWyC/uv9uuRUxdto9681RwptsFKdqMF9LB1RuenDujSS TC8X2hgTG4ljQC4gb4p7d6aLxSPAEs2RYNaaamHJ5141tg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (a.mx.sigpipe.cz) smtp.remote-ip=37.221.242.114; dmarc=none header.from=sigpipe.cz; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1628595276; bh=brqS4lXHSP7WQTHAeXd0mMvF60K/a0snhtETWJSs5eA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=IGNfMerGhmzrg+GtpJ1PRwn9X53iV1vT1vEgw3TKKYJLixG48lf9W8S71H8IZKnppn4KddHcnp Ogqb2Cj119IbFHi9DXwZ74HiqmNOG9tA4I1TAvStwB4KAhLH3PT1MLPNnnIGlhjl4M8vxT16DG OZt6vmt2gFUbskG7IWDotg4zNiqX/2GWeup651IsQRd6FhS+SLbVEvttHGFH8uajMI2eoHpwfP VRxAk2xEmvIlrlrPnouOCVE4MnEKLXTIfd9RGyLBfCWrQuZmma7I3/Wk7Y2Y4TXR7vhRxsQsRZ jujwRvt0pI5cCu5gLnLvrquSYRsAp2T+g5ddhmqyoj0UWw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=veY0kAUzXJXVYC86LNv4hxckZ6DCDb7wOaaiz/7o80c=; b=TWlkRmf5mHwD7lvE8FtYqInLAJ OMg/Kjolji9i76xILdDuj6+JFCg99CLV2jlsY8kB1MR2efBMMyf1lFSmYZ97ccZiLHzK+nPUatZtn Pp7kwbdtpQxqZdcHcLsKoyPQsnXdVkebJi7jP0gPmTY1OGyb1k0wmoFXj2fEmaYBkl9Lq73wfOvpw WnWqlqR9cCAXRp8n+ZL1PY9lq0A2d1sX80oAQiFrAOUQGP9OQ3cQJluovEhG7rCjH3OOl8+MAiEYs rgp3KjyECflIBmaAnU/1kFpQIz/X7dzkZTfveNas56tAxfVSqZtr8Uk/NehF1EJDYmZYahgXl7iZh f5fyjU7Q==; Received: from authenticated user by zero.zsh.org with local id 1mDQ1j-000EGl-9P; Tue, 10 Aug 2021 11:34:35 +0000 Authentication-Results: zsh.org; iprev=pass (a.mx.sigpipe.cz) smtp.remote-ip=37.221.242.114; dmarc=none header.from=sigpipe.cz; arc=none Received: from a.mx.sigpipe.cz ([37.221.242.114]:2371) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mDQ0l-000DZY-6m; Tue, 10 Aug 2021 11:33:37 +0000 Received: by a.mx.sigpipe.cz (Postfix, from userid 1001) id EA3C5155866733; Tue, 10 Aug 2021 13:33:33 +0200 (CEST) Date: Tue, 10 Aug 2021 13:33:33 +0200 From: Roman Neuhauser To: Bart Schaefer Cc: Zsh Users Subject: Re: chpwd, precmd hooks have "zsh" in $0 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 26888 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: # schaefer@brasslantern.com / 2021-08-09 14:26:58 -0700: > On Mon, Aug 9, 2021 at 1:16 PM Roman Neuhauser wrote: > > > > as the subject says, at least the chpwd and precmd hooks > > have the shell's argv[0] in $0. > > This is because (most) hook functions are called with an empty (NULL) > argument list, as opposed to e.g. all commands (external, builtin, or > function) run from a command line, which have a non-empty argument > list starting with the command name itself. > > In the particular case of preexec, the argument list is empty any time > history is not active, which is the case when loading a script with > "source" or "." builtins. If you actually try it from the interactive > command line, you'll see that $0 is "preexec" in the call to every > function in the preexec_functions list. how did this happen? was it the shortest patch that wouldn't crash the shell? you give no hints of benefits this should have for users, and i can't think of any either. come to think of it, if so taxing to implement fully, why is it built into the shell in the first place? and is it too late to reverse the course, gut the half-assed implementation with one written using shell functions? so much in zsh is done that way, why is the loop over foo_functions written in C? > I'm not sure what the desired behavior is here. callhookfunc() could > dummy up a LinkNode any time its lnklst argument is empty, and then > all the hooks would behave in the manner preexec behaves when history > is enabled; or doshfunc() could do the same, in which case every > hook-array function would have its own name in $0; or neither of the > above is appropriate and we should document the current behavior. what are the downsides of (2) for users of the shell? both (1) and (3) result in loss of information and deviation from standard behavior, and what is lost in behavior is gained in length of the manual. (2) preserves information, gets rid of a special case, and nullifies the need for more documentation. that is, i'm assuming that functions plugged into any hook behave as actual functions, IOW function a b { ... } > ab.log precmd_functions=(a) preexec_functions=(b) calls the function with $0 == "a" in precmd, "b" in preexec, and that their runtime output goes to ab.log. hooks do neither and TRAPNAL functions only the first. :( -- roman