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

Re: cd, pwd and symlinks



On Sep 28, 12:07pm, Peter Stephenson wrote:
} Subject: Re: cd, pwd and symlinks
}
} "Stefan Monnier" wrote:
} >That's indeed what I'm complaining about.  The default behavior is very
} >non-unixish which is surprising for a unix-only tool.
} 
} In that case, ksh is non-UNIXish too, since it has this logical path
} feature on by default.  (Plus it's still able to change up from a
} no-longer-existent directory, which zsh isn't after the last round of
} cd changes, but we had this discussion at length some months ago.)

Hm.  I thought "cd .." was only supposed to fail if chasedots was set.
"cd ." or "cd ../$PWD:t" are supposed to fail if the destination doesn't
exist.  But this is a side-effect of "cd .." turning into "cd $PWD/.."
plus the rule that "cd /some/missing/directory/.." is supposed to fail,
isn't it.  Argh.
 
} > But how hard would it be to have `pwd' do a stat("$PWD") and stat(".")
} > and compare the inode to make sure the current $PWD is still valid ?
} 
} It does seem that this could be improved.

I can't decide whether I object to this ... but perhaps it should at least
not happen when ksh emulation is in effect?

} This isn't perfect, since unless you run pwd, the shell doesn't know if the
} path to the current directory became invalid and a cd can still fail, but
} at least it gives you a natural way of fixing it.

A bit confusing, though, isn't it?

zsh% cd /tmp/test
zsh% cd subdir
zsh: No such file or directory: subdir
zsh% pwd
/tmp/renamed
zsh% cd subdir
zsh% 

If there were much elapsed time at all between the first two cd's, the
poor user might not remember where he was before the pwd, and would have
no idea what was going on.

And finally, `dirs` still outputs the previous value of PWD.

} There's some reason why the code was changed
} to do all changes with absolute path --- maybe to simplify it, hur hur.

As far as I can tell, this is something Zefram changed between 3.1.2 and
3.1.3, for which no patch was ever posted.

} I'm sure other people will have completely different ideas, they always do
} with directories.

Indeed.  I may have a look at this later today if I get a chance.  I'm
thinking that (a) pwd should do something more like cd_new_pwd() (but not
including calling chpwd) if it can't stat(pwd), and (b) cd should try
harder, perhaps implicitly behaving as if chasedots, if it can't stat(pwd).

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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