zsh-workers
 help / color / mirror / code / Atom feed
* autocd in scripts
@ 2014-11-08 13:44 Clint Hepner
  2014-11-08 19:04 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Clint Hepner @ 2014-11-08 13:44 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

A question on Stack Overflow recently asked about using the AUTO_CD option
in a script,
as it did not appear to work. I couldn't find anything in the documentation
about it, but a
peek at exec.c revealed that for

    setopt autocd
    mkdir foo
    foo
    # $pwd is now foo

to work, the SHIN_STDIN option needs to be in effect as well:

    # Src/exec.c, execcmd()
    char trycd = (isset(AUTOCD) && isset(SHINSTDIN) &&
                      (!redir || empty(redir)) && args && !empty(args) &&
                      !nextnode(firstnode(args)) && *(char
*)peekfirst(args));

I realize AUTO_CD is intended as an interactive feature, but requiring
commands be read
from standard input seems like a proxy for checking if the shell is
interactive. I was
wondering if there was a reason for this specific check, and if it could
either be relaxed
or documented with AUTO_CD.

Clint

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: autocd in scripts
  2014-11-08 13:44 autocd in scripts Clint Hepner
@ 2014-11-08 19:04 ` Bart Schaefer
  2014-11-08 20:28   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2014-11-08 19:04 UTC (permalink / raw)
  To: Clint Hepner; +Cc: Zsh hackers list

On Sat, Nov 8, 2014 at 5:44 AM, Clint Hepner <clint.hepner@gmail.com> wrote:
>
> A question on Stack Overflow recently asked about using the AUTO_CD option
> in a script

My first reaction to this would be "Why?" -- under what circumstances
would you want to obscure the fact that the script is changing
directories? -- but to return to the direct question ...

> I couldn't find anything in the documentation
[but]
> the SHIN_STDIN option needs to be in effect as well:
>
> I realize AUTO_CD is intended as an interactive feature, but requiring commands be read
> from standard input seems like a proxy for checking if the shell is interactive. I was
> wondering if there was a reason for this specific check, and if it could either be relaxed
> or documented with AUTO_CD.

The SHINSTDIN test has been part of autocd farther back than any
changelog or source control can resolve, so it's probably related to
cd printing out the name of the new directory whenever an autocd takes
place, and the assumption is that this would not be wanted when the
input is from a script file (but simply changing silently would also
be bad).

This probably should be documented somehow.  Suggested wording, anyone?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: autocd in scripts
  2014-11-08 19:04 ` Bart Schaefer
@ 2014-11-08 20:28   ` Peter Stephenson
  2014-11-08 23:29     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2014-11-08 20:28 UTC (permalink / raw)
  To: Zsh hackers list

On Sat, 8 Nov 2014 11:04:42 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> The SHINSTDIN test has been part of autocd farther back than any
> changelog or source control can resolve, so it's probably related to
> cd printing out the name of the new directory whenever an autocd takes
> place, and the assumption is that this would not be wanted when the
> input is from a script file (but simply changing silently would also
> be bad).
> 
> This probably should be documented somehow.  Suggested wording, anyone?

SHINSTDIN seems to be fairly fully documented, I suppose we just refer
to it from the AUTOCD entry.

I'm torn between wondering whether we need to be writing a style guide
to scripting or simply standing over users while they write out 100
times "I must not use confusing interactive features in scripts".

pws


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: autocd in scripts
  2014-11-08 20:28   ` Peter Stephenson
@ 2014-11-08 23:29     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2014-11-08 23:29 UTC (permalink / raw)
  To: Zsh hackers list

diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 452b258..93887ca 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -63,6 +63,10 @@ item(tt(AUTO_CD) (tt(-J)))(
 If a command is issued that can't be executed as a normal command,
 and the command is the name of a directory, perform the tt(cd)
 command to that directory.
+This option is only applicable if the option tt(SHIN_STDIN) is set,
+i.e. if commands are being read from standard input.  The option
+is designed for interactive use; it is recommended that tt(cd)
+be used explicitly in scripts to avoid ambiguity.
 )
 pindex(AUTO_PUSHD)
 pindex(NO_AUTO_PUSHD)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-11-08 23:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-08 13:44 autocd in scripts Clint Hepner
2014-11-08 19:04 ` Bart Schaefer
2014-11-08 20:28   ` Peter Stephenson
2014-11-08 23:29     ` Peter Stephenson

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).