* ZSH_SCRIPT @ 2016-02-24 17:34 Greg Klanderman 2016-02-24 22:31 ` ZSH_SCRIPT Bart Schaefer 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-02-24 17:34 UTC (permalink / raw) To: Zsh list Hi guys, Sorry I dropped the ball on this topic back in early 2011, see discussion in thread 'loading user startup files for zsh scripts', specifically workers 28735 and followups: http://www.zsh.org/mla/workers/2011/msg00173.html Unfortunately I had thought we had agreed ZSH_SCRIPT should only be set/non-empty in the case where you are actually running a script, but this is not what has been recently implemented. I would still like a way to tell if running a script or not. I am slowly working out of a large backlog of stuff that got dropped when the startup I work for got acquired about 5 years back, and am hoping to get back to tieing up some loose ends like this in the not too distant future.. Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-02-24 17:34 ZSH_SCRIPT Greg Klanderman @ 2016-02-24 22:31 ` Bart Schaefer 2016-02-25 9:33 ` ZSH_SCRIPT Peter Stephenson 0 siblings, 1 reply; 28+ messages in thread From: Bart Schaefer @ 2016-02-24 22:31 UTC (permalink / raw) To: Zsh list On Feb 24, 12:34pm, Greg Klanderman wrote: } } Sorry I dropped the ball on this topic back in early 2011, see } discussion in thread 'loading user startup files for zsh scripts', I don't think anyone else remembered that this had been discussed before. The choice of ZSH_SCRIPT as a parameter name was convergent evolution. Personally I'd be fine with ZSH_SCRIPT being unset at the top level, but there are considerations of POSIX_ARGZERO etc. now which didn't exist at the time of the 2011 thread. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-02-24 22:31 ` ZSH_SCRIPT Bart Schaefer @ 2016-02-25 9:33 ` Peter Stephenson 2016-02-25 17:59 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Peter Stephenson @ 2016-02-25 9:33 UTC (permalink / raw) To: Zsh list On Wed, 24 Feb 2016 14:31:53 -0800 Bart Schaefer <schaefer@brasslantern.com> wrote: > On Feb 24, 12:34pm, Greg Klanderman wrote: > } > } Sorry I dropped the ball on this topic back in early 2011, see > } discussion in thread 'loading user startup files for zsh scripts', > > I don't think anyone else remembered that this had been discussed before. > The choice of ZSH_SCRIPT as a parameter name was convergent evolution. > > Personally I'd be fine with ZSH_SCRIPT being unset at the top level, but > there are considerations of POSIX_ARGZERO etc. now which didn't exist at > the time of the 2011 thread. The variable is new --- we could have a different one to make the POSIX $0 permanently available. pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-02-25 9:33 ` ZSH_SCRIPT Peter Stephenson @ 2016-02-25 17:59 ` Greg Klanderman 2016-02-25 23:04 ` ZSH_SCRIPT Bart Schaefer 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-02-25 17:59 UTC (permalink / raw) To: zsh-workers >>>>> On February 25, 2016 Peter Stephenson <p.stephenson@samsung.com> wrote: > The variable is new --- we could have a different one to make the POSIX > $0 permanently available. Hi Peter and Bart, Are you saying this is new enough that it can still be changed? I would be OK leaving it, and adding another variable as I had originally proposed, but I do think that ZSH_SCRIPT is a bit better name for what I had originally proposed, i.e. the name of the script or empty, and that something like ZSH_ARGZERO might be better for what is currently called ZSH_SCRIPT. LKM what you prefer, and if you want me to submit a patch. thank you, Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-02-25 17:59 ` ZSH_SCRIPT Greg Klanderman @ 2016-02-25 23:04 ` Bart Schaefer 2016-02-29 23:36 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Bart Schaefer @ 2016-02-25 23:04 UTC (permalink / raw) To: zsh-workers On Feb 25, 12:59pm, Greg Klanderman wrote: } } Are you saying this is new enough that it can still be changed? That's how I interpret what Peter said, yes. I don't really have any preference here. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-02-25 23:04 ` ZSH_SCRIPT Bart Schaefer @ 2016-02-29 23:36 ` Greg Klanderman 2016-03-01 9:27 ` ZSH_SCRIPT Peter Stephenson 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-02-29 23:36 UTC (permalink / raw) To: zsh-workers >>>>> On February 25, 2016 Bart Schaefer <schaefer@brasslantern.com> wrote: > On Feb 25, 12:59pm, Greg Klanderman wrote: > } > } Are you saying this is new enough that it can still be changed? > That's how I interpret what Peter said, yes. I don't really have any > preference here. OK, Peter what do you prefer? Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-02-29 23:36 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-01 9:27 ` Peter Stephenson 2016-03-01 14:39 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Peter Stephenson @ 2016-03-01 9:27 UTC (permalink / raw) To: zsh-workers On Mon, 29 Feb 2016 18:36:18 -0500 Greg Klanderman <gak@klanderman.net> wrote: > >>>>> On February 25, 2016 Bart Schaefer <schaefer@brasslantern.com> wrote: > > > On Feb 25, 12:59pm, Greg Klanderman wrote: > > } > > } Are you saying this is new enough that it can still be changed? > > > That's how I interpret what Peter said, yes. I don't really have any > > preference here. > > OK, Peter what do you prefer? I'm happy with ZSH_SCRIPT only being set for the script and something else like ZSH_ARGZERO indicating the POSIX $0, if that makes sense. pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-01 9:27 ` ZSH_SCRIPT Peter Stephenson @ 2016-03-01 14:39 ` Greg Klanderman 2016-03-01 15:07 ` ZSH_SCRIPT Peter Stephenson 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-03-01 14:39 UTC (permalink / raw) To: zsh-workers >>>>> On March 1, 2016 Peter Stephenson <p.stephenson@samsung.com> wrote: > I'm happy with ZSH_SCRIPT only being set for the script and something > else like ZSH_ARGZERO indicating the POSIX $0, if that makes sense. Thank you Peter & Bart.. how about this? Should we explicitly document that ZSH_SCRIPT is empty rather than unset when not invoked as a script? thanks, Greg diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ae859ce..a3ce880 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,14 @@ 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. +) 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 *))); ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-01 14:39 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-01 15:07 ` Peter Stephenson 2016-03-01 16:36 ` ZSH_SCRIPT Greg Klanderman 2016-03-02 19:34 ` ZSH_SCRIPT Martijn Dekker 0 siblings, 2 replies; 28+ messages in thread From: Peter Stephenson @ 2016-03-01 15:07 UTC (permalink / raw) To: zsh-workers On Tue, 1 Mar 2016 09:39:19 -0500 Greg Klanderman <gak@klanderman.net> wrote: > Should we explicitly document that ZSH_SCRIPT is empty rather than > unset when not invoked as a script? That would probably be sensible. pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-01 15:07 ` ZSH_SCRIPT Peter Stephenson @ 2016-03-01 16:36 ` Greg Klanderman 2016-03-01 18:36 ` ZSH_SCRIPT Bart Schaefer 2016-03-02 19:34 ` ZSH_SCRIPT Martijn Dekker 1 sibling, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-03-01 16:36 UTC (permalink / raw) To: zsh-workers >>>>> On March 1, 2016 Peter Stephenson <p.stephenson@samsung.com> 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 *))); ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-01 16:36 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-01 18:36 ` Bart Schaefer 2016-03-01 20:14 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Bart Schaefer @ 2016-03-01 18:36 UTC (permalink / raw) To: zsh-workers On Mar 1, 11:36am, Greg Klanderman wrote: } } parseargs(argv, &runscript, &cmd); } + zsh_script = runscript; I think that should probably be ztrdup(runscript) the same way argzero and posixzero are handled, but maybe this next bit makes it unnecessary. } setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); } - setsparam("ZSH_SCRIPT", ztrdup(posixzero)); } + setsparam("ZSH_ARGZERO", ztrdup(posixzero)); } + setsparam("ZSH_SCRIPT", ztrdup(zsh_script)); Those should probably be ztrdup_metafy() same as ZSH_NAME. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-01 18:36 ` ZSH_SCRIPT Bart Schaefer @ 2016-03-01 20:14 ` Greg Klanderman 2016-03-02 9:30 ` ZSH_SCRIPT Peter Stephenson 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-03-01 20:14 UTC (permalink / raw) To: zsh-workers 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 *))); ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-01 20:14 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-02 9:30 ` Peter Stephenson 2016-03-02 15:48 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Peter Stephenson @ 2016-03-02 9:30 UTC (permalink / raw) To: zsh-workers On Tue, 1 Mar 2016 15:14:17 -0500 Greg Klanderman <gak@klanderman.net> wrote: > 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. No, the new variables come from an argument and these are already metafied very early on in zsh_main by for (t = argv; *t; *t = metafy(*t, -1, META_ALLOC), t++); Look around and you'll see none of the other uses of command line arguments don't get further metafied, either (including posixzero which is related to the new ones). The things that need metafying when turned into variables come from the environment (including the working directory). pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-02 9:30 ` ZSH_SCRIPT Peter Stephenson @ 2016-03-02 15:48 ` Greg Klanderman 2016-03-02 15:56 ` ZSH_SCRIPT Peter Stephenson 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-03-02 15:48 UTC (permalink / raw) To: zsh-workers >>>>> On March 2, 2016 Peter Stephenson <p.stephenson@samsung.com> wrote: > No, the new variables come from an argument and these are already > metafied very early on in zsh_main by > for (t = argv; *t; *t = metafy(*t, -1, META_ALLOC), t++); OK, I will change those two back to ztrdup() sans metify. Should I add a comment to that effect? Did you want this ztrdup in or not: zsh_script = ztrdup(runscript); > Look around and you'll see none of the other uses of command line > arguments don't get further metafied, either (including posixzero > which is related to the new ones). > The things that need metafying when turned into variables come from > the environment (including the working directory). It looks like ZSH_NAME comes from argv[0] immediately after the early metification you pointed out above, but is being re-metified here: setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-02 15:48 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-02 15:56 ` Peter Stephenson 2016-03-02 21:33 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Peter Stephenson @ 2016-03-02 15:56 UTC (permalink / raw) To: zsh-workers On Wed, 2 Mar 2016 10:48:42 -0500 Greg Klanderman <gak@klanderman.net> wrote: > Did you want this ztrdup in or not: > > zsh_script = ztrdup(runscript); I think it makes sense (unless it's duplicated again). > It looks like ZSH_NAME comes from argv[0] immediately after the early > metification you pointed out above, but is being re-metified here: > > setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); That's probably wrong for the reasons I gave, unless I'm missing something basic. pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-02 15:56 ` ZSH_SCRIPT Peter Stephenson @ 2016-03-02 21:33 ` Greg Klanderman 0 siblings, 0 replies; 28+ messages in thread From: Greg Klanderman @ 2016-03-02 21:33 UTC (permalink / raw) To: zsh-workers >>>>> On March 2, 2016 Peter Stephenson <p.stephenson@samsung.com> wrote: > On Wed, 2 Mar 2016 10:48:42 -0500 > Greg Klanderman <gak@klanderman.net> wrote: >> Did you want this ztrdup in or not: >> >> zsh_script = ztrdup(runscript); > I think it makes sense (unless it's duplicated again). well, as it currently stands there is that ztrdup() shown above in zsh_main() and then another here in createparamtable(): setsparam("ZSH_SCRIPT", ztrdup(zsh_script)); Yesterday, a few emails back in this thread Bart had said he thought there should probably be a ztrdup() in zsh_main() but that maybe it was not needed due to the one in createparamtable(). >> It looks like ZSH_NAME comes from argv[0] immediately after the early >> metification you pointed out above, but is being re-metified here: >> >> setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); > That's probably wrong for the reasons I gave, unless I'm missing > something basic. OK, I will fix that in the next version of the patch I send. Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-01 15:07 ` ZSH_SCRIPT Peter Stephenson 2016-03-01 16:36 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-02 19:34 ` Martijn Dekker 2016-03-02 21:24 ` ZSH_SCRIPT Greg Klanderman 1 sibling, 1 reply; 28+ messages in thread From: Martijn Dekker @ 2016-03-02 19:34 UTC (permalink / raw) To: zsh-workers Peter Stephenson schreef op 01-03-16 om 16:07: > On Tue, 1 Mar 2016 09:39:19 -0500 > Greg Klanderman <gak@klanderman.net> wrote: >> Should we explicitly document that ZSH_SCRIPT is empty rather than >> unset when not invoked as a script? > > That would probably be sensible. Is there a particular reason why it should be empty rather than unset? Unset seems more logical; if we're not running a script, the script name is not the empty string but it doesn't exist. This would also make it possible to do [[ -v ZSH_SCRIPT ]] to check if you're in a script. - M. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-02 19:34 ` ZSH_SCRIPT Martijn Dekker @ 2016-03-02 21:24 ` Greg Klanderman 2016-03-03 9:37 ` ZSH_SCRIPT Peter Stephenson 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-03-02 21:24 UTC (permalink / raw) To: zsh-workers >>>>> On March 2, 2016 Martijn Dekker <martijn@inlv.org> wrote: > Is there a particular reason why it should be empty rather than unset? > Unset seems more logical; if we're not running a script, the script name > is not the empty string but it doesn't exist. This would also make it > possible to do > [[ -v ZSH_SCRIPT ]] > to check if you're in a script. Hi Martijn, I'm happy to do it either way, but went with what had been discussed about 5 years ago when both Bart and Peter seemed to prefer empty to unset: http://www.zsh.org/mla/workers/2011/msg00183.html Bart> I think empty is OK, but let's hear from PWS. PWS> I think empty is much more Zen-like, so fits perfectly. Bart and Peter, can you let me know if that still holds? Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-02 21:24 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-03 9:37 ` Peter Stephenson 2016-03-03 17:26 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Peter Stephenson @ 2016-03-03 9:37 UTC (permalink / raw) To: zsh-workers On Wed, 2 Mar 2016 16:24:13 -0500 Greg Klanderman <gak@klanderman.net> wrote: > >>>>> On March 2, 2016 Martijn Dekker <martijn@inlv.org> wrote: > > > Is there a particular reason why it should be empty rather than unset? > > Unset seems more logical; if we're not running a script, the script name > > is not the empty string but it doesn't exist. This would also make it > > possible to do > > [[ -v ZSH_SCRIPT ]] > > to check if you're in a script. > > Hi Martijn, I'm happy to do it either way, but went with what had > been discussed about 5 years ago when both Bart and Peter seemed to > prefer empty to unset: > > http://www.zsh.org/mla/workers/2011/msg00183.html > > Bart> I think empty is OK, but let's hear from PWS. > > PWS> I think empty is much more Zen-like, so fits perfectly. > > Bart and Peter, can you let me know if that still holds? I don't think we ever had a major preference. The only real objection to it being unset is an error is if you test [[ -z $ZSH_SCRIPT ]] and NO_UNSET is set. This is much more likely for a zsh programmer than the rarely used -v. On the other hand, ${+ZSH_SCRIPT} is a standard zsh idiom which is quite widely used. However, as it's a new variable, it really doesn't matter that much as long as it's documented. There's a rather minor objection that if it's not set in a shell function you might think the shell never sets it and use it yourself. But programming by assumption isn't very healthy. I can't think of anything else. So I really don't think it makes a lot of difference. pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-03 9:37 ` ZSH_SCRIPT Peter Stephenson @ 2016-03-03 17:26 ` Greg Klanderman 2016-03-03 17:37 ` ZSH_SCRIPT Peter Stephenson 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-03-03 17:26 UTC (permalink / raw) To: zsh-workers >>>>> On March 3, 2016 Peter Stephenson <p.stephenson@samsung.com> wrote: > I can't think of anything else. So I really don't think it makes a lot > of difference. OK, I think I agree with Martijn and prefer unset to empty, so will make that change. Peter/Bart do you think it needs both ztrdup()s? in zsh_main(): zsh_script = ztrdup(runscript); and in createparamtable(): setsparam("ZSH_SCRIPT", ztrdup(zsh_script)); Let me know and I will send an updated patch. thanks, Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-03 17:26 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-03 17:37 ` Peter Stephenson 2016-03-03 19:36 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Peter Stephenson @ 2016-03-03 17:37 UTC (permalink / raw) To: zsh-workers On Thu, 3 Mar 2016 12:26:22 -0500 Greg Klanderman <gak@klanderman.net> wrote: > Peter/Bart do you think it needs both ztrdup()s? > > in zsh_main(): > zsh_script = ztrdup(runscript); > > and in createparamtable(): > setsparam("ZSH_SCRIPT", ztrdup(zsh_script)); I think it needs the second, because what you pass to a parameter needs to be uniquely managed by that parameter, so it can't point to memory that can be referenced another way. I doubt it needs the first as well. Actually, I don't see why you need a glboal for zsh_script at all. It's just there to pass runscript on so it can be set later. That's better done by passing arguments rather than globals. pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-03 17:37 ` ZSH_SCRIPT Peter Stephenson @ 2016-03-03 19:36 ` Greg Klanderman 2016-03-03 20:39 ` ZSH_SCRIPT Peter Stephenson 2016-03-03 20:44 ` ZSH_SCRIPT Bart Schaefer 0 siblings, 2 replies; 28+ messages in thread From: Greg Klanderman @ 2016-03-03 19:36 UTC (permalink / raw) To: zsh-workers >>>>> On March 3, 2016 Peter Stephenson <p.stephenson@samsung.com> wrote: > I think it needs the second, because what you pass to a parameter needs > to be uniquely managed by that parameter, so it can't point to memory > that can be referenced another way. I doubt it needs the first as well. > Actually, I don't see why you need a glboal for zsh_script at all. It's > just there to pass runscript on so it can be set later. That's better > done by passing arguments rather than globals. OK how do you like this? Greg diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ae859ce..d23c459 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 unset. +) 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..87e7430 100644 --- a/Src/init.c +++ b/Src/init.c @@ -802,7 +802,7 @@ init_term(void) /**/ void -setupvals(char *cmd) +setupvals(char *cmd, char *runscript) { #ifdef USE_GETPWUID struct passwd *pswd; @@ -1042,7 +1042,7 @@ setupvals(char *cmd) createshfunctable(); /* create hash table for shell functions */ createbuiltintable(); /* create hash table for builtin commands */ createnameddirtable(); /* create hash table for named directories */ - createparamtable(); /* create parameter hash table */ + createparamtable(runscript); /* create parameter hash table */ condtab = NULL; wrappers = NULL; @@ -1660,7 +1660,7 @@ zsh_main(UNUSED(int argc), char **argv) SHTTY = -1; init_io(cmd); - setupvals(cmd); + setupvals(cmd, runscript); init_signals(); init_bltinmods(); diff --git a/Src/params.c b/Src/params.c index 8bd8a8e..ecd5bfb 100644 --- a/Src/params.c +++ b/Src/params.c @@ -667,7 +667,7 @@ split_env_string(char *env, char **name, char **value) /**/ void -createparamtable(void) +createparamtable(char *runscript) { Param ip, pm; #if !defined(HAVE_PUTENV) && !defined(USE_SET_UNSET_ENV) @@ -812,8 +812,10 @@ createparamtable(void) setsparam("OSTYPE", ztrdup_metafy(OSTYPE)); setsparam("TTY", ztrdup_metafy(ttystrname)); setsparam("VENDOR", ztrdup_metafy(VENDOR)); - setsparam("ZSH_NAME", ztrdup_metafy(zsh_name)); - setsparam("ZSH_SCRIPT", ztrdup(posixzero)); + setsparam("ZSH_NAME", ztrdup(zsh_name)); /* NOTE: command line arguments are metafied early in zsh_main() */ + setsparam("ZSH_ARGZERO", ztrdup(posixzero)); + if (runscript) + setsparam("ZSH_SCRIPT", ztrdup(runscript)); setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION)); setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL)); setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *))); ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-03 19:36 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-03 20:39 ` Peter Stephenson 2016-03-03 20:44 ` ZSH_SCRIPT Bart Schaefer 1 sibling, 0 replies; 28+ messages in thread From: Peter Stephenson @ 2016-03-03 20:39 UTC (permalink / raw) To: zsh-workers On Thu, 03 Mar 2016 14:36:52 -0500 Greg Klanderman <gak@klanderman.net> wrote: > OK how do you like this? Looks good to me, unless my brain is drifting with Scottish dancing cribs. pws ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-03 19:36 ` ZSH_SCRIPT Greg Klanderman 2016-03-03 20:39 ` ZSH_SCRIPT Peter Stephenson @ 2016-03-03 20:44 ` Bart Schaefer 2016-03-03 20:50 ` ZSH_SCRIPT Bart Schaefer 1 sibling, 1 reply; 28+ messages in thread From: Bart Schaefer @ 2016-03-03 20:44 UTC (permalink / raw) To: zsh-workers On Mar 3, 2:36pm, Greg Klanderman wrote: } } OK how do you like this? Sorry to seem mercurial, but I don't think there's any real reason that all those set?param() calls need to be inside createparamtable(). It could just as easily be [note precedent exists] diff --git a/Src/init.c b/Src/init.c index 4097327..5bad342 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1089,6 +1089,8 @@ setupvals(char *cmd) if (cmd) setsparam("ZSH_EXECUTION_STRING", ztrdup(cmd)); + if (runscript) + setsparam("ZSH_SCRIPT", ztrdup(runscript)); } /* -- Barton E. Schaefer ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-03 20:44 ` ZSH_SCRIPT Bart Schaefer @ 2016-03-03 20:50 ` Bart Schaefer 2016-03-04 2:07 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Bart Schaefer @ 2016-03-03 20:50 UTC (permalink / raw) To: zsh-workers On Mar 3, 12:44pm, Bart Schaefer wrote: } Subject: Re: ZSH_SCRIPT } } Sorry to seem mercurial, but I don't think there's any real reason that } all those set?param() calls need to be inside createparamtable(). For that matter, it appears the zsh_name global could also be localized to zsh_main() and then passed down to setupvals(). No need to set that in createparamtable() either. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-03 20:50 ` ZSH_SCRIPT Bart Schaefer @ 2016-03-04 2:07 ` Greg Klanderman 2016-03-05 16:22 ` ZSH_SCRIPT Bart Schaefer 0 siblings, 1 reply; 28+ messages in thread From: Greg Klanderman @ 2016-03-04 2:07 UTC (permalink / raw) To: zsh-workers >>>>> On March 3, 2016 Bart Schaefer <schaefer@brasslantern.com> wrote: > On Mar 3, 12:44pm, Bart Schaefer wrote: > } Subject: Re: ZSH_SCRIPT > } > } Sorry to seem mercurial, but I don't think there's any real reason that > } all those set?param() calls need to be inside createparamtable(). > For that matter, it appears the zsh_name global could also be localized > to zsh_main() and then passed down to setupvals(). No need to set that > in createparamtable() either. No problem, how do you like this? Greg diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ae859ce..d23c459 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 unset. +) 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..20a07eb 100644 --- a/Src/init.c +++ b/Src/init.c @@ -802,7 +802,7 @@ init_term(void) /**/ void -setupvals(char *cmd) +setupvals(char *cmd, char *runscript, char *zsh_name) { #ifdef USE_GETPWUID struct passwd *pswd; @@ -1089,6 +1089,9 @@ setupvals(char *cmd) if (cmd) setsparam("ZSH_EXECUTION_STRING", ztrdup(cmd)); + if (runscript) + setsparam("ZSH_SCRIPT", ztrdup(runscript)); + setsparam("ZSH_NAME", ztrdup(zsh_name)); /* NOTE: already metafied early in zsh_main() */ } /* @@ -1270,7 +1273,7 @@ run_init_scripts(void) /**/ void -init_misc(char *cmd) +init_misc(char *cmd, char *zsh_name) { #ifndef RESTRICTED_R if ( restricted ) @@ -1606,7 +1609,7 @@ mod_export int use_exit_printed; mod_export int zsh_main(UNUSED(int argc), char **argv) { - char **t, *runscript = NULL; + char **t, *runscript = NULL, *zsh_name; char *cmd; /* argument to -c */ int t0; #ifdef USE_LOCALE @@ -1660,14 +1663,14 @@ zsh_main(UNUSED(int argc), char **argv) SHTTY = -1; init_io(cmd); - setupvals(cmd); + setupvals(cmd, runscript, zsh_name); init_signals(); init_bltinmods(); init_builtins(); run_init_scripts(); setupshin(runscript); - init_misc(cmd); + init_misc(cmd, zsh_name); for (;;) { /* diff --git a/Src/params.c b/Src/params.c index 8bd8a8e..51ee886 100644 --- a/Src/params.c +++ b/Src/params.c @@ -80,8 +80,7 @@ char *argzero, /* $0 */ *rprompt, /* $RPROMPT */ *rprompt2, /* $RPROMPT2 */ *sprompt, /* $SPROMPT */ - *wordchars, /* $WORDCHARS */ - *zsh_name; /* $ZSH_NAME */ + *wordchars; /* $WORDCHARS */ /**/ mod_export char *ifs, /* $IFS */ @@ -812,8 +811,7 @@ createparamtable(void) setsparam("OSTYPE", ztrdup_metafy(OSTYPE)); 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_VERSION", ztrdup_metafy(ZSH_VERSION)); setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL)); setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *))); ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-04 2:07 ` ZSH_SCRIPT Greg Klanderman @ 2016-03-05 16:22 ` Bart Schaefer 2016-03-05 20:03 ` ZSH_SCRIPT Greg Klanderman 0 siblings, 1 reply; 28+ messages in thread From: Bart Schaefer @ 2016-03-05 16:22 UTC (permalink / raw) To: zsh-workers On Mar 3, 9:07pm, Greg Klanderman wrote: } } No problem, how do you like this? Looks good to me. Are you able to push or does one of us need to commit this? ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: ZSH_SCRIPT 2016-03-05 16:22 ` ZSH_SCRIPT Bart Schaefer @ 2016-03-05 20:03 ` Greg Klanderman 0 siblings, 0 replies; 28+ messages in thread From: Greg Klanderman @ 2016-03-05 20:03 UTC (permalink / raw) To: zsh-workers >>>>> On March 5, 2016 Bart Schaefer <schaefer@brasslantern.com> wrote: > Looks good to me. Are you able to push or does one of us need to commit > this? I can't push, can one of you please do so? thank you, Greg ^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2016-03-05 20:03 UTC | newest] Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 ` ZSH_SCRIPT Greg Klanderman 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
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).