From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28074 invoked by alias); 5 Feb 2016 22:33:29 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37895 Received: (qmail 29677 invoked from network); 5 Feb 2016 22:33:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Originating-IP: [82.20.18.64] X-Spam: 0 X-Authority: v=2.1 cv=aIwN0uJm c=1 sm=1 tr=0 a=tQ56d2wE10i0ATcm3CvKvA==:117 a=tQ56d2wE10i0ATcm3CvKvA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=hD80L64hAAAA:8 a=txVAmrA_BdSt4ISbnfgA:9 a=CjuIK1q_8ugA:10 Date: Fri, 5 Feb 2016 22:27:50 +0000 From: Peter Stephenson To: Zsh hackers list Subject: Re: PATCH: funcstack[-1] (formerly Suppress tracing of "set +x") Message-ID: <20160205222750.1fda3574@ntlworld.com> In-Reply-To: <20160205160236.1274aa5b@pwslap01u.europe.root.pri> References: <20151230104531.GA20496@linux.vnet.ibm.com> <5683F898.7010907@inlv.org> <20160205100902.GA14979@linux.vnet.ibm.com> <20160205102735.1f09973a@pwslap01u.europe.root.pri> <20160205104444.2437ad33@pwslap01u.europe.root.pri> <20160205160236.1274aa5b@pwslap01u.europe.root.pri> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 5 Feb 2016 10:44:44 +0000 Peter Stephenson wrote: > Drifting a bit away from the original topic... I tried to improve this > so you didn't get the "(anon)" in the PS4 output, instead something more > useful. I came up with this... > > () { > setopt localoptions promptsubst > PS4=${PS4//\%N/'${funcstack[2]:-$0}'} > setopt xtrace > # some command > } > > This sort of works, but it struck me that it's harder than it might be > to get the name of the top level script. (Finally moved this to zsh-workers.) Here's a much simpler way. It strikes me that actually I could have set POSIX_ARGZERO, but maybe this is useful. By the way, looking at the code I just notice that the following isn't an error even though it doesn't do what you presumably expect: % setopt posixargzero % print $0 zsh % 0=foo % print $0 zsh Maybe that's OK so far, but you don't even get the value back when you unset the option; it's silently lost. It seems a bit pointless since you'd get the same value of $0 with POSIX_ARGZERO set even if it stored the value in the normal argzero space the way it seems to imply it did. pws diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 6722092..159a5bb 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -951,6 +951,13 @@ track of versions of the shell during development between releases; hence most users should not use it and should instead rely on tt($ZSH_VERSION). ) +vindex(ZSH_SCRIPT) +item(tt(ZSH_SCRIPT))( +If zsh was inovked to run a script, this is the name of the script. +Otherwise, the name used to invoke the current shell. This is +the same as the value of tt($0) when the tt(POSIX_ARGZERO) option is +set, but is always available. +) item(tt(zsh_scheduled_events))( See ifzman(the section `The zsh/sched Module' in zmanref(zshmodules))\ ifnzman(noderef(The zsh/sched Module)). diff --git a/Src/params.c b/Src/params.c index 76ed61c..0233e2b 100644 --- a/Src/params.c +++ b/Src/params.c @@ -813,6 +813,7 @@ createparamtable(void) setsparam("TTY", ztrdup_metafy(ttystrname)); setsparam("VENDOR", ztrdup_metafy(VENDOR)); setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); + setsparam("ZSH_SCRIPT", ztrdup(posixzero)); setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION)); setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL)); setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));