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

Re: can we have an option for cd to do a plain chdir()



I started looking at this myself a while back but couldn't find a way
to untangle the function dependencies.  They're oddly factored and
other parts of the shell depend on some of the bits in the middle.
For example ...

On Sun, Feb 6, 2022 at 9:44 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> $ strace -fe getcwd,readlink,chdir,fchdir zsh -c 'cd link'
> readlink("/proc/self/fd/0", "/dev/pts/4", 4095) = 10
> chdir("/home/chazelas/link")            = 0
> chdir("/home/chazelas/link")            = 0
> +++ exited with 0 +++
>
> Not sure why the two chdir()s there.

I'm pretty sure that's because there's first a chdir() via
cd_try_chdir() which might fail (e.g., searching cdpath), and then
once the full path has been confirmed there's another chdir() to make
sure the shell is actually in the directory that was found.

It has long felt to me as though the whole thing could be simplified,
but I set it aside after a few of my attempts broke various
special-case semantics.  I'm also not certain that Test/B01cd.ztst is
comprehensive in terms of catching possible regressions.




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