ajeetdsouza / zoxide

A smarter cd command. Supports all major shells.
MIT License
20.54k stars 523 forks source link

zoxide cannot find the `cd` command #686

Closed UtkarshVerma closed 5 months ago

UtkarshVerma commented 5 months ago

I have a common shell configuration file named shellrc where I initialise zoxide as follows:

if command -v zoxide >/dev/null 2>&1; then
    eval "$(zoxide init posix --hook prompt)"
fi

This works and in my zsh shell, I can see the z command. However, when I try to open a directory, I get the following:

$ z downloads
__zoxide_cd:2: command not found: cd

I have investigated this to be caused by the following implementation.

__zoxide_cd () {
    \command cd "$@"
}

Here is what fails on zsh:

$ command cd
zsh: command not found: cd

This works on other shells like dash and bash.

ajeetdsouza commented 5 months ago

What zsh version are you running? command cd works fine on zsh for me.

UtkarshVerma commented 5 months ago

I am using v5.9.

$ zsh --version
zsh 5.9 (x86_64-pc-linux-gnu)
ajeetdsouza commented 5 months ago

zsh appears to differ from POSIX shells here. Whereas in other shells you would use command cd, on zsh you need to use builtin cd unless the POSIX_BUILTINS option is set.

Possible solutions:

UtkarshVerma commented 5 months ago

Thanks, using setopt posixbuiltins did the job for me.