zsh-workers
 help / color / mirror / code / Atom feed
From: Greg Klanderman <gak@klanderman.net>
To: zsh-workers@zsh.org
Subject: Re: ZSH_SCRIPT
Date: Tue, 01 Mar 2016 15:14:17 -0500	[thread overview]
Message-ID: <871t7u7y7a.fsf@lwm.klanderman.net> (raw)
In-Reply-To: <160301103630.ZM8094@torch.brasslantern.com> (Bart Schaefer's message of "Tue, 1 Mar 2016 10:36:30 -0800")


Hi Bart, I wasn't sure if by "probably" you wanted someone (Peter?) to
comment but I think adding ztrdup should be safe and ztrdup_metafy is
used for the other variables so almost has to be right; here is an
updated patch.

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..4b33ad2 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 = ztrdup(runscript);
 
     SHTTY = -1;
     init_io(cmd);
diff --git a/Src/params.c b/Src/params.c
index 8bd8a8e..58dddc4 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_metafy(posixzero));
+    setsparam("ZSH_SCRIPT", ztrdup_metafy(zsh_script));
     setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION));
     setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL));
     setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));


  reply	other threads:[~2016-03-01 20:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-24 17:34 ZSH_SCRIPT Greg Klanderman
2016-02-24 22:31 ` ZSH_SCRIPT Bart Schaefer
2016-02-25  9:33   ` ZSH_SCRIPT Peter Stephenson
2016-02-25 17:59     ` ZSH_SCRIPT Greg Klanderman
2016-02-25 23:04       ` ZSH_SCRIPT Bart Schaefer
2016-02-29 23:36         ` ZSH_SCRIPT Greg Klanderman
2016-03-01  9:27           ` ZSH_SCRIPT Peter Stephenson
2016-03-01 14:39             ` ZSH_SCRIPT Greg Klanderman
2016-03-01 15:07               ` ZSH_SCRIPT Peter Stephenson
2016-03-01 16:36                 ` ZSH_SCRIPT Greg Klanderman
2016-03-01 18:36                   ` ZSH_SCRIPT Bart Schaefer
2016-03-01 20:14                     ` Greg Klanderman [this message]
2016-03-02  9:30                       ` ZSH_SCRIPT Peter Stephenson
2016-03-02 15:48                         ` ZSH_SCRIPT Greg Klanderman
2016-03-02 15:56                           ` ZSH_SCRIPT Peter Stephenson
2016-03-02 21:33                             ` ZSH_SCRIPT Greg Klanderman
2016-03-02 19:34                 ` ZSH_SCRIPT Martijn Dekker
2016-03-02 21:24                   ` ZSH_SCRIPT Greg Klanderman
2016-03-03  9:37                     ` ZSH_SCRIPT Peter Stephenson
2016-03-03 17:26                       ` ZSH_SCRIPT Greg Klanderman
2016-03-03 17:37                         ` ZSH_SCRIPT Peter Stephenson
2016-03-03 19:36                           ` ZSH_SCRIPT Greg Klanderman
2016-03-03 20:39                             ` ZSH_SCRIPT Peter Stephenson
2016-03-03 20:44                             ` ZSH_SCRIPT Bart Schaefer
2016-03-03 20:50                               ` ZSH_SCRIPT Bart Schaefer
2016-03-04  2:07                                 ` ZSH_SCRIPT Greg Klanderman
2016-03-05 16:22                                   ` ZSH_SCRIPT Bart Schaefer
2016-03-05 20:03                                     ` ZSH_SCRIPT Greg Klanderman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871t7u7y7a.fsf@lwm.klanderman.net \
    --to=gak@klanderman.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).