Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Opts -i and -s no longer work together, haven't for while



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



Messages sorted by: Reverse Date, Date, Thread, Author