zsh-workers
 help / color / mirror / code / Atom feed
From: Greg Klanderman <gak@klanderman.net>
To: zsh-workers@zsh.org
Subject: Re: loading user startup files for zsh scripts
Date: Fri, 11 Feb 2011 11:28:43 -0500	[thread overview]
Message-ID: <m339nucz7o.fsf@klanderman.net> (raw)
In-Reply-To: <110210192945.ZM31349@torch.brasslantern.com> (Bart Schaefer's message of "Thu, 10 Feb 2011 19:29:45 -0800")

>>>>> On February 10, 2011 Bart Schaefer <schaefer@brasslantern.com> wrote:

> This is odd considering that $* has already been set to the script
> arguments by the time .zshenv is processed.  It also means that zsh
> will read all the init files before discovering that it can't read
> the script file.

This appears to be due to support for the (undocumented) PATHSCRIPT
option, whereby the path is searched for the runscript, and therefore
the startup files must be read first so that PATH can be set properly.

> I'm also finding it a little weird that $0 apparently might be a
> metafied string, since setupshin() believes that unmeta(runscript)
> is necessary before calling e.g. access().

Did you note this line near the top of zsh_main():

|    for (t = argv; *t; *t = metafy(*t, -1, META_ALLOC), t++);

i.e. all the argv arguments are metified early on.

> I'm inclined to suggest ZSH_SCRIPT to be initialized from runscript.

How is the patch below?  I can add doc if you like it.. one open
question is whether you want $ZSH_SCRIPT to be unset or empty when not
running a script; currently it would be empty, which might be useful
for detecting whether zsh is providing that parameter.

> I'd also like to get ZSH_INTERPRETER to be the actual path to the shell
> executable, but I suspect that's not universally available from the OS.

Didn't touch this one.

> Returning to your original problem ... I don't suppose all these user's
> hosts are running linux?  You can examine /proc/$$/cmdline to find out
> if a script name appears.

Oooh that's tricky, yes all are a variety of linux distros, mostly
debian/ubuntu and FC/RHEL/Centos.  Still would have to parse it and
deal with the nul byte separators, yuck.

Greg


Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.118
diff -u -r1.118 init.c
--- Src/init.c	11 Feb 2011 04:04:05 -0000	1.118
+++ Src/init.c	11 Feb 2011 16:22:50 -0000
@@ -1485,6 +1485,7 @@
     opts[USEZLE] = 1;   /* may be unset in init_io() */
     /* sets INTERACTIVE, SHINSTDIN and SINGLECOMMAND */
     parseargs(argv, &runscript);
+    zsh_script = runscript;
 
     SHTTY = -1;
     init_io();
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.169
diff -u -r1.169 params.c
--- Src/params.c	16 Jan 2011 20:35:31 -0000	1.169
+++ Src/params.c	11 Feb 2011 16:22:51 -0000
@@ -80,7 +80,8 @@
      *rprompt2,		/* $RPROMPT2    */
      *sprompt,		/* $SPROMPT     */
      *wordchars,	/* $WORDCHARS   */
-     *zsh_name;		/* $ZSH_NAME    */
+     *zsh_name,		/* $ZSH_NAME    */
+     *zsh_script;	/* $ZSH_SCRIPT  */
 /**/
 mod_export
 char *ifs,		/* $IFS         */
@@ -779,6 +780,7 @@
     setsparam("TTY", ztrdup(ttystrname));
     setsparam("VENDOR", ztrdup(VENDOR));
     setsparam("ZSH_NAME", ztrdup(zsh_name));
+    setsparam("ZSH_SCRIPT", ztrdup(zsh_script));
     setsparam("ZSH_VERSION", ztrdup(ZSH_VERSION));
     setsparam("ZSH_PATCHLEVEL", ztrdup(ZSH_PATCHLEVEL));
     setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));


  reply	other threads:[~2011-02-11 16:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-07 20:34 Greg Klanderman
2011-02-08  5:33 ` Bart Schaefer
2011-02-08 17:09   ` Greg Klanderman
2011-02-08 17:20     ` Peter Stephenson
2011-02-09  0:37       ` Greg Klanderman
2011-02-09  4:58         ` Bart Schaefer
2011-02-09 15:32           ` Greg Klanderman
2011-02-09 16:01           ` Greg Klanderman
2011-02-09 16:53             ` Bart Schaefer
2011-02-10 16:30               ` Greg Klanderman
2011-02-10 17:52                 ` Bart Schaefer
2011-02-10 23:10                   ` Greg Klanderman
2011-02-11  1:42                   ` Greg Klanderman
2011-02-11  3:29                     ` Bart Schaefer
2011-02-11 16:28                       ` Greg Klanderman [this message]
2011-02-11 17:26                         ` Bart Schaefer
2011-02-11 17:47                           ` Peter Stephenson
2011-02-11 18:36                           ` Bart Schaefer
2011-02-11 19:25                         ` Peter Stephenson

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=m339nucz7o.fsf@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).