zsh-users
 help / color / mirror / code / Atom feed
* cd - and $OLDPWD, bug in the manual?
@ 2006-03-23 21:08 Francisco Borges
  2006-03-26  7:36 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Francisco Borges @ 2006-03-23 21:08 UTC (permalink / raw)
  To: Zsh User

Hello all,

Some weeks ago I received lot's of help and comments a question about
"dirstack history". Thanks a lot. Now I'm not only happier, I'm also a
bit lazier.

[...]

Sometimes (but not all the time) I want to login and go immediately to
the last dir I was before logging out. Which I could do using "% cd -1",
but lazy as I am, I tried to do

% cd -

and this failed... I checked the manual and it says:

cd [ -sLP ] {+|-}n

   [...] specified.  If arg is `-', change to the value of $OLDPWD, the
   previous directory.

I tried setting OLDPWD, but "% cd -" would still not work.

This time I actually took a look into the code and indeed, "cd -" is not
using $OLDPWD, just a variable whose value should be reflected into the
value of $OLDPWD.

Do you guys agree with me that either the manual or
Src/builtin.c:cd_get_dest need to change?

Cheers,
Francisco


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

* Re: cd - and $OLDPWD, bug in the manual?
  2006-03-23 21:08 cd - and $OLDPWD, bug in the manual? Francisco Borges
@ 2006-03-26  7:36 ` Bart Schaefer
  2006-03-26 17:07   ` [zsh] " Francisco Borges
  2006-03-26 18:40   ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2006-03-26  7:36 UTC (permalink / raw)
  To: Zsh User

On Mar 23, 10:08pm, Francisco Borges wrote:
}
} Do you guys agree with me that either the manual or
} Src/builtin.c:cd_get_dest need to change?

To cut right to the chase ... no.

} Sometimes (but not all the time) I want to login and go immediately to
} the last dir I was before logging out. Which I could do using "% cd -1",
} but lazy as I am, I tried to do
} 
} % cd -
} 
} and this failed... I checked the manual and it says:
} 
} cd [ -sLP ] {+|-}n
} 
}    [...] specified.  If arg is `-', change to the value of $OLDPWD, the
}    previous directory.

The manual also says (note "Set" not "Used" here):

Parameters Set By The Shell

OLDPWD
     The previous working directory.  This is set when the shell
     initializes and whenever the directory changes.

And in fact "cd -" DOES change to the value of OLDPWD *that was set by
the shell when it initialized*.  It just happens that initially PWD and
OLDPWD are set to the same thing, because there has been no "cd" yet.

} I tried setting OLDPWD, but "% cd -" would still not work.

The manual DOESN'T say that you can have any useful effect by assigning
OLDPWD.  You can assign to PWD as well, but that doesn't cause a "cd"
to magically occur.

The doc for "cd" could be marginally clearer if it said e.g. ...

    If arg is `-', change to the previous directory, normally the value
    of $OLDPWD.

... but would that have helped you?


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

* Re: [zsh] Re: cd - and $OLDPWD, bug in the manual?
  2006-03-26  7:36 ` Bart Schaefer
@ 2006-03-26 17:07   ` Francisco Borges
  2006-03-26 18:40   ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Francisco Borges @ 2006-03-26 17:07 UTC (permalink / raw)
  To: Zsh User

» On Sat, Mar 25, 2006 at 11:36PM -0800, Bart Schaefer wrote:

> The manual also says (note "Set" not "Used" here):
>
> Parameters Set By The Shell
>
> OLDPWD
>      The previous working directory.  This is set when the shell
>      initializes and whenever the directory changes.

Indeed I didn't read the OLDPWD entry. Thanks for pointing it out.

> The manual DOESN'T say that you can have any useful effect by
> assigning OLDPWD.  You can assign to PWD as well, but that doesn't
> cause a "cd" to magically occur.

I don't expect anything, except for the prompt, to automatically change
after an "export" without issuing any other command. (Whether that's
actually the case is beyond the point here.) I didn't expect this for
PWD nor for OLDPWD.

But I did expect "cd -" to change to the value of OLDPWD.

How did I come up with such a crazy, nonsensical idea?

By reading the manual, which *explicitly* states that this would
happen. No more, no less.

> The doc for "cd" could be marginally clearer if it said e.g. ...
>
>     If arg is `-', change to the previous directory, normally the value
>     of $OLDPWD.
>
> ... but would that have helped you?

Honestly, I'm sure it would.

Because it was the particular wording at the "cd" entry that got me into
trying to use the *value* of OLDPWD to influence "cd -".

IMHO this is not the case of being "marginally clearer" but about being
"technically accurate".

Regards,
Francisco


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

* Re: cd - and $OLDPWD, bug in the manual?
  2006-03-26  7:36 ` Bart Schaefer
  2006-03-26 17:07   ` [zsh] " Francisco Borges
@ 2006-03-26 18:40   ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2006-03-26 18:40 UTC (permalink / raw)
  To: Zsh User, pws

Bart Schaefer wrote:
> The manual DOESN'T say that you can have any useful effect by assigning
> OLDPWD.  You can assign to PWD as well, but that doesn't cause a "cd"
> to magically occur.

We could make OLDPWD settable by making it special, though I don't think
we're morally obliged to.  Spoofing the previous directory sort of makes
sense.  Spoofing the current directory doesn't, at least not without
opening a large can of worms.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page still at http://www.pwstephenson.fsnet.co.uk/


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

end of thread, other threads:[~2006-03-26 18:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-23 21:08 cd - and $OLDPWD, bug in the manual? Francisco Borges
2006-03-26  7:36 ` Bart Schaefer
2006-03-26 17:07   ` [zsh] " Francisco Borges
2006-03-26 18:40   ` 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).