* Opts -i and -s no longer work together, haven't for while @ 2014-10-11 6:12 Bart Schaefer 2014-10-11 16:52 ` Bart Schaefer 0 siblings, 1 reply; 5+ messages in thread From: Bart Schaefer @ 2014-10-11 6:12 UTC (permalink / raw) To: zsh-workers Here's zsh-2.4 (wow, ancient): schaefer[792] src/zsh -si <<<'echo foo' torch<502> foo torch<503> % (exited -- the % there is the newer zsh printing the end-of-line mark) But by the time we get to zsh-3.0.5: schaefer[794] Src/zsh -fsi <<<'echo foo' torch% (the shell is now reading from the terminal and ignores stdin) I have no idea whether that was intentional. Bash appears to work like zsh-2.4 did. The doc for -i explicitly says -i Force shell to be interactive. It is still possible to specify a script to execute. but as far as I can tell "zsh -i" always simply sets $@ and never treats its first argument as a script file. So this has been broken for about 25 years ... ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Opts -i and -s no longer work together, haven't for while 2014-10-11 6:12 Opts -i and -s no longer work together, haven't for while Bart Schaefer @ 2014-10-11 16:52 ` Bart Schaefer 2014-10-11 20:07 ` Bart Schaefer 0 siblings, 1 reply; 5+ messages in thread From: Bart Schaefer @ 2014-10-11 16:52 UTC (permalink / raw) To: zsh-workers On Oct 10, 11:12pm, Bart Schaefer wrote: } } But by the time we get to zsh-3.0.5: } } schaefer[794] Src/zsh -fsi <<<'echo foo' } torch% } } (the shell is now reading from the terminal and ignores stdin) So the problem appears to be that ZLE remains enabled whenever the standard OUTPUT is a terminal, even if the standard INPUT is not, and having ZLE turned on (as it is by default from sometime after 2.4) overrides everything else, ignores the command line script file name, and reads from the terminal. So you have to use "zsh +Z -fi ..." to get the effect I expected. Do we want to change this, or document it? We'd have to move the default setting of opts[USEZLE] from zsh_main() into parseargs(), I think. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Opts -i and -s no longer work together, haven't for while 2014-10-11 16:52 ` Bart Schaefer @ 2014-10-11 20:07 ` Bart Schaefer 2014-10-12 17:06 ` Peter Stephenson 0 siblings, 1 reply; 5+ messages in thread From: Bart Schaefer @ 2014-10-11 20:07 UTC (permalink / raw) To: zsh-workers On Oct 11, 9:52am, Bart Schaefer wrote: } } So the problem appears to be that ZLE remains enabled whenever the } standard OUTPUT is a terminal, even if the standard INPUT is not It's actually worse than that, it acquires /dev/tty if std(in|out|err) are redirected, so you really do have to use +Z to make it work. } Do we want to change this, or document it? We'd have to move the } default setting of opts[USEZLE] from zsh_main() into parseargs(), } I think. There are a couple of ways to spin this. We can either disable ZLE any time the -s option is given, or we can set ZLE from isatty(0) when -s is given. The latter is more consistent with the past two decades of behavior. Then we have to decide what to do of -Z is explicitly given. There is also the effect of SINGLECOMMAND (-t) to consider; it overrides -Z and turns off prompting as well, unless -i is given along with it. So I think -s should also take precedence. So, please give feedback on this patch. To compare with the previous behavior, try these test cases: zsh -fs <<<setopt # should work the same before/after zsh +Z -fs <<<setopt # should work the same before/after zsh +Z -fis <<<setopt # should work the same before/after zsh -fis <<<setopt # should differ zsh -Z -fis <<<setopt # should differ zsh -fist <<<setopt # differ zsh -fi =(<<<setopt) # same zsh -ft =(<<<setopt) # same zsh -Z -ft =(<<<setopt) # same zsh -fit =(<<<setopt) # same diff --git a/Src/init.c b/Src/init.c index 6d005dc..c4da7a3 100644 --- a/Src/init.c +++ b/Src/init.c @@ -243,12 +243,22 @@ parseargs(char **argv, char **runscript) */ opts[MONITOR] = 2; /* may be unset in init_io() */ opts[HASHDIRS] = 2; /* same relationship to INTERACTIVE */ + opts[USEZLE] = 1; /* see below, related to SHINSTDIN */ opts[SHINSTDIN] = 0; opts[SINGLECOMMAND] = 0; if (parseopts(NULL, &argv, opts, &cmd, NULL)) exit(1); + /* + * USEZLE remains set if the shell has access to a terminal and + * is not reading from some other source as indicated by SHINSTDIN. + * SHINSTDIN becomes set below if there is no command argument, + * but it is the explicit setting (or not) that matters to USEZLE. + */ + if (opts[SHINSTDIN]) + opts[USEZLE] = (opts[USEZLE] && isatty(0)); + paramlist = znewlinklist(); if (*argv) { if (unset(SHINSTDIN)) { @@ -1608,8 +1618,7 @@ zsh_main(UNUSED(int argc), char **argv) emulate(zsh_name, 1, &emulation, opts); /* initialises most options */ opts[LOGINSHELL] = (**argv == '-'); opts[PRIVILEGED] = (getuid() != geteuid() || getgid() != getegid()); - opts[USEZLE] = 1; /* may be unset in init_io() */ - /* sets INTERACTIVE, SHINSTDIN and SINGLECOMMAND */ + /* sets ZLE, INTERACTIVE, SHINSTDIN and SINGLECOMMAND */ parseargs(argv, &runscript); SHTTY = -1; -- Barton E. Schaefer ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Opts -i and -s no longer work together, haven't for while 2014-10-11 20:07 ` Bart Schaefer @ 2014-10-12 17:06 ` Peter Stephenson 2014-10-12 17:42 ` Bart Schaefer 0 siblings, 1 reply; 5+ messages in thread From: Peter Stephenson @ 2014-10-12 17:06 UTC (permalink / raw) To: zsh-workers On Sat, 11 Oct 2014 13:07:08 -0700 Bart Schaefer <schaefer@brasslantern.com> wrote: > } Do we want to change this, or document it? We'd have to move the > } default setting of opts[USEZLE] from zsh_main() into parseargs(), > } I think. > > There are a couple of ways to spin this. We can either disable ZLE > any time the -s option is given, or we can set ZLE from isatty(0) > when -s is given. The latter is more consistent with the past two > decades of behavior. Probably be good to allow ZLE if there's away of doing it, yes. > Then we have to decide what to do of -Z is explicitly given. There > is also the effect of SINGLECOMMAND (-t) to consider; it overrides -Z > and turns off prompting as well, unless -i is given along with it. > So I think -s should also take precedence. From what you're saying, two decades of behaviour haven't done anyone much use at all when combining -i and -s --- the -s is effectively ignroed. So actually I don't think it's all that crucial as long as the only changes are where both are given, which is what you're suggesting: > zsh -fis <<<setopt # should differ > zsh -Z -fis <<<setopt # should differ > zsh -fist <<<setopt # differ -s being the part of the business that has been ignored, it's hard to see how making it take precedence now can break anything that was working and that logically should have worked. So it all sounds fine to me. pws ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Opts -i and -s no longer work together, haven't for while 2014-10-12 17:06 ` Peter Stephenson @ 2014-10-12 17:42 ` Bart Schaefer 0 siblings, 0 replies; 5+ messages in thread From: Bart Schaefer @ 2014-10-12 17:42 UTC (permalink / raw) To: zsh-workers On Oct 12, 6:06pm, Peter Stephenson wrote: } } -s being the part of the business that has been ignored, it's hard to } see how making it take precedence now can break anything that was } working and that logically should have worked. So it all sounds fine } to me. Here's a revised patch that also fixes a couple of other small items: I added a bit more detail to the comment in parseargs() because the comment mentioning init_io() was removed from zsh_main(). The caller of init_io() expects that shout might become NULL, but the setvbuf() call in init_io() did not consider that possibility. The word "interative" in a comment was a typo. diff --git a/Src/init.c b/Src/init.c index 6d005dc..68d3612 100644 --- a/Src/init.c +++ b/Src/init.c @@ -243,12 +243,24 @@ parseargs(char **argv, char **runscript) */ opts[MONITOR] = 2; /* may be unset in init_io() */ opts[HASHDIRS] = 2; /* same relationship to INTERACTIVE */ + opts[USEZLE] = 1; /* see below, related to SHINSTDIN */ opts[SHINSTDIN] = 0; opts[SINGLECOMMAND] = 0; if (parseopts(NULL, &argv, opts, &cmd, NULL)) exit(1); + /* + * USEZLE remains set if the shell has access to a terminal and + * is not reading from some other source as indicated by SHINSTDIN. + * SHINSTDIN becomes set below if there is no command argument, + * but it is the explicit setting (or not) that matters to USEZLE. + * USEZLE may also become unset in init_io() if the shell is not + * interactive or the terminal cannot be re-opened read/write. + */ + if (opts[SHINSTDIN]) + opts[USEZLE] = (opts[USEZLE] && isatty(0)); + paramlist = znewlinklist(); if (*argv) { if (unset(SHINSTDIN)) { @@ -603,7 +615,7 @@ init_shout(void) if (SHTTY == -1) { - /* Since we're interative, it's nice to have somewhere to write. */ + /* Since we're interactive, it's nice to have somewhere to write. */ shout = stderr; return; } @@ -616,7 +628,8 @@ init_shout(void) /* Associate terminal file descriptor with a FILE pointer */ shout = fdopen(SHTTY, "w"); #ifdef _IOFBF - setvbuf(shout, shoutbuf, _IOFBF, BUFSIZ); + if (shout) + setvbuf(shout, shoutbuf, _IOFBF, BUFSIZ); #endif gettyinfo(&shttyinfo); /* get tty state */ @@ -1608,8 +1621,7 @@ zsh_main(UNUSED(int argc), char **argv) emulate(zsh_name, 1, &emulation, opts); /* initialises most options */ opts[LOGINSHELL] = (**argv == '-'); opts[PRIVILEGED] = (getuid() != geteuid() || getgid() != getegid()); - opts[USEZLE] = 1; /* may be unset in init_io() */ - /* sets INTERACTIVE, SHINSTDIN and SINGLECOMMAND */ + /* sets ZLE, INTERACTIVE, SHINSTDIN and SINGLECOMMAND */ parseargs(argv, &runscript); SHTTY = -1; -- Barton E. Schaefer ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-10-12 17:42 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-10-11 6:12 Opts -i and -s no longer work together, haven't for while Bart Schaefer 2014-10-11 16:52 ` Bart Schaefer 2014-10-11 20:07 ` Bart Schaefer 2014-10-12 17:06 ` Peter Stephenson 2014-10-12 17:42 ` Bart Schaefer
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).