Subject: Re: ZSH_SCRIPT
From: Greg Klanderman <[email-masked]>
To: [email-masked]
Date: Tue, 01 Mar 2016 11:36:53 -0500
List-Id: Zsh Workers List <zsh-workers.zsh.org>

>>>>> On March 1, 2016 Peter Stephenson <[email-masked]> wrote:

> That would probably be sensible.

How's this?

Greg

diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index ae859ce..716c523 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -933,6 +933,13 @@ tt(zsh/zutil) module.
 )
 enditem()
 )
+vindex(ZSH_ARGZERO)
+item(tt(ZSH_ARGZERO))(
+If zsh was invoked to run a script, this is the name of the script.
+Otherwise, it is 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.
+)
 vindex(ZSH_EXECUTION_STRING)
 item(tt(ZSH_EXECUTION_STRING))(
 If the shell was started with the option tt(-c), this contains
@@ -951,17 +958,15 @@ 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 invoked to run a script, this is the name of the script.
-Otherwise, it is 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)).
 )
+vindex(ZSH_SCRIPT)
+item(tt(ZSH_SCRIPT))(
+If zsh was invoked to run a script, this is the name of the script,
+otherwise it is the empty string.
+)
 vindex(ZSH_SUBSHELL <S>)
 item(tt(ZSH_SUBSHELL))(
 Readonly integer.  Initially zero, incremented each time the shell forks
diff --git a/Src/init.c b/Src/init.c
index 4097327..e96ad2c 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1657,6 +1657,7 @@ zsh_main(UNUSED(int argc), char **argv)
     opts[PRIVILEGED] = (getuid() != geteuid() || getgid() != getegid());
     /* sets ZLE, INTERACTIVE, SHINSTDIN and SINGLECOMMAND */
     parseargs(argv, &runscript, &cmd);
+    zsh_script = runscript;
 
     SHTTY = -1;
     init_io(cmd);
diff --git a/Src/params.c b/Src/params.c
index 8bd8a8e..c6c6d82 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -81,7 +81,8 @@ char *argzero,		/* $0           */
      *rprompt2,		/* $RPROMPT2    */
      *sprompt,		/* $SPROMPT     */
      *wordchars,	/* $WORDCHARS   */
-     *zsh_name;		/* $ZSH_NAME    */
+     *zsh_name,		/* $ZSH_NAME    */
+     *zsh_script;	/* $ZSH_SCRIPT  */
 /**/
 mod_export
 char *ifs,		/* $IFS         */
@@ -813,7 +814,8 @@ 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_ARGZERO", ztrdup(posixzero));
+    setsparam("ZSH_SCRIPT", ztrdup(zsh_script));
     setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION));
     setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL));
     setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));