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=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7902 invoked from network); 10 Aug 2021 17:31:54 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Aug 2021 17:31:54 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1628616714; b=kFDtWcCchz88GKpMuQ8aqV/2N15HVFhErSqz5JeSJ9vRyFk0WvQVg4bk9zml77shk8RTC89cKq JFwam9MPMv6CVMS+ROKN4YhkwHMlVulQIy46BYXksSRWR/ZCCErFhhC11AQN/18zhp7cg0QwI0 usJuEIQq3nCLUb1IVX/CYY3fWQuLgvrdYHZ5kbimqSPrpjD8E3wMXRyx5fiCkNxYybKWkdSmjs ixhXej4PxFbr56+4Cc0qH9cL3/CcmUK7jeC8Q7Oglg/+GXBv79Z5WfgygC1uE+5BNYRDU0dOZE pQVwMTFcH8Y5TVh9d9LiCcRb+zpXgyMeL/Y4PX2vqQXLuQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f171.google.com) smtp.remote-ip=209.85.219.171; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1628616714; bh=NfbIqyr9HrkWFMpdEUL6F+gJe6Qz/WEYWNoZijeH4nA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=mR+/akDhraxqwwxxAeoMozGBlI6MQqJl/TPjXYgv6gun4RahHSfI5m5gNx3lvP2+n1Oi4iz7pb KbvowKSHoSNDli6iDfcVxuDKC3qJNjtHCFHngwdV+zA8DI7pPaDe90HJCUxKH5r0VoL3yuB0fl iSkvY1uYdC9WgrnfJTCNIBpXDt3c2YF1xxEcRXhLYyjkYo4BRImQOUp5ml+yLdEj8SJNAjJKTh yTVkM0HwLbw0FVYGTQdeo9FZv1qs5tk27Ea5eqsNHEhE86+Lrb24ndFru3Zd951l7ddCXkGov4 I+KzouLLEg1vKPWWQdK8U4CCXMJM4Cy7vRkIjQ/LOtszJA==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=UM34EbLOpbe6IFDQ+ZqNSAbSq3FqcO7BL1EFWLw+Uw4=; b=dtTP3jHIrBxUv8gOoJeeTheooM FYuFkm7eWJbdyf+mLrdOT2LhMJzPTYICHXeBUdMvHjIqrNImH8NDNOl8kxzcwmLc3dB/Q8Ubks2yV rDlkk78dY9jhFaqrrVYB6EQf+0Ui7+RjRfGZOA95mz0iBWDdBd/vBSEYjxeLixk5ZeTW3cwgPfNpC OKbsHWAMKl4+aD+fWKINUvF95WxUOBboXUUnpxb8dO2FvrANJlkMi5QcsVQGmtUulL473koeIqic2 IL/3EHIii+ZgzMbje89grEELN8GgfT2qj3numCT4midZ2VS6UJY2RHU16DqZvmyzZwZJ60tOk/zMm HrsECQQg==; Received: from authenticated user by zero.zsh.org with local id 1mDVbV-000BiL-NO; Tue, 10 Aug 2021 17:31:53 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f171.google.com) smtp.remote-ip=209.85.219.171; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yb1-f171.google.com ([209.85.219.171]:39673) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mDVaq-000B0M-Il; Tue, 10 Aug 2021 17:31:14 +0000 Received: by mail-yb1-f171.google.com with SMTP id p145so37544013ybg.6 for ; Tue, 10 Aug 2021 10:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UM34EbLOpbe6IFDQ+ZqNSAbSq3FqcO7BL1EFWLw+Uw4=; b=Jdn56gm5FA8OmZbjMx9lJHUwx3Ikd5kNdQS2UTF2GH3ig0Zoyp2bHIdF3LL0nUnkGs n9v62HAuMo5sP6Y5mcixQAe/Xvya3K7N8r7eCAo0+rrHEeoB9KD5xTM8DSCvBwiZKxkq jsvbaNncVAG66B51FAXsUTR8Wt/WMdgKDxaH0QOkb1VVgzdxP3Wzp9fKfYkKr2QRxnB8 d1F92ac5FXpSzYCwsGftkaw6Iobx/+xm4CFN0ebCf3e85hVfrk2s9Jh1sQQZW4z2m+3O JEY9CKxImYJEMxYMl4ZOi0XOD64VJd65BMjfV4Wfc41ndSUSNargsw0XhpTwi+B8eOBG UYkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UM34EbLOpbe6IFDQ+ZqNSAbSq3FqcO7BL1EFWLw+Uw4=; b=FiSREVLqEXkX9n3nkLgcfTC2LBlXEN6WiGiYfNzEXVmDlh2SMPC+Ry7Mdvs/1izlgf GOL5kT1b9TbArF616Wemz1gghAFVIfErqi97li9QdL0oqT0CLOqDqfxDyHMYiJg1CUY7 W8luDezjP6KaSwAouokIVggMKstFIMyQoKWq6T6FZ4Kc1RI18IFOyCi/a/5zgTHE0BbA 0A18LeDgAws3fD8R6rkDk/bxuunGEtQd80WogOphPaFuucW4urD4gqqczhHQiKLeCW+g A128Ssonx0Aw4ZxD4M3DZZApFydfkzsiB2knYII/DykprcBin4UPKogMir4NAqYfGxUz qnsQ== X-Gm-Message-State: AOAM532Et5FksgiNXgYrZ0N9ahU5a454K7rd1VoJhmaSX3KWyb1dZ85m 3fpyYutwy9PHA4/z2OATl0KEznI83T6rwy9T7Okh8/5H6Xd/Pw== X-Google-Smtp-Source: ABdhPJygx7Sozf6cSpdYSTpHB2EH/35avacDZPB83JK987x6pBV1HcLrHUm02yzqKmI2xt+horIRC6lZe9In1gjICCc= X-Received: by 2002:a25:dc8e:: with SMTP id y136mr4308300ybe.14.1628616671150; Tue, 10 Aug 2021 10:31:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Tue, 10 Aug 2021 10:31:00 -0700 Message-ID: Subject: Re: chpwd, precmd hooks have "zsh" in $0 To: Roman Neuhauser Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26896 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: On Tue, Aug 10, 2021 at 4:33 AM Roman Neuhauser wrote: > > how did this happen? I return to what I told Marlon the other day: The answer to "why doesn't feature A take advantage of feature B" is often "because A was developed long before B". The code for calling the hook functions has been around since long before the FUNCTION_ARGZERO option was added, and nobody thought to update all the entry points. When the code for the arrays of hooks was further added, it just passed through what the base function was already getting. > come to think of it, if so taxing to implement fully, why is it built > into the shell in the first place? It's not "taxing", it's just forgotten. It was built into the C code so that people's existing hook functions (precmd, preexec, chpwd, etc.) wouldn't have to be changed/overwritten to "know about" the new special arrays, and so that e.g. module writers could plug into those arrays without fear that a user could change the calling protocol. > and is it too late to reverse the > course, gut the half-assed implementation with one written using shell > functions? There's no need to be offensive about it, but yes, it's too late. The implementation actually has all the interfaces it needs to populate FUNCTION_ARGZERO properly, it was just never noticed/found necessary to do so. > > 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? Theoretically, a function might prefer to know that it was being called as a consequence of being found in a given hook list, vs. being called directly. That might argue for (1). However, since the current situation is (3), the only instance where that could exist in practice is for the preexec hooks, so we're probably safe choosing (2). I will note, to avoid yet again having an "A forgot B" situation, that Zftp module hooks also behave like (3) and would begin to have their own name in $0 if we change doshfunc(). > 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. :( I'm not sure what "the first" is here? Anyway, having output redirections on function definitions is another thing that was added quite late in the long history of the shell -- originally, the redirect would have been connected to the "function" command itself -- so there may be circumstances where you have to write function a b { { ... } > ab.log } to be sure of getting what you meant there. PWS may have more to say about it.