Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zoxide cannot find the cd command #686

Closed
UtkarshVerma opened this issue Feb 11, 2024 · 4 comments
Closed

zoxide cannot find the cd command #686

UtkarshVerma opened this issue Feb 11, 2024 · 4 comments

Comments

@UtkarshVerma
Copy link

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
Copy link
Owner

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

@ajeetdsouza ajeetdsouza added the waiting-for-response Waiting for a response from the issue author. label Feb 12, 2024
@UtkarshVerma
Copy link
Author

I am using v5.9.

$ zsh --version
zsh 5.9 (x86_64-pc-linux-gnu)

@github-actions github-actions bot removed the waiting-for-response Waiting for a response from the issue author. label Feb 13, 2024
@ajeetdsouza
Copy link
Owner

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:

  • We could add custom logic to the POSIX script to handle zsh. However, given that there is a dedicated initialization script for zsh, I don't think it makes much sense to do that.
  • You could initialize zoxide in the RC file of each shell, rather than have a common one for all shells. This way, you will also get access to shell completions.
  • Enable POSIX_BUILTINS in zsh. This will make zsh POSIX-compliant, and zoxide will start working again.

@UtkarshVerma
Copy link
Author

Thanks, using setopt posixbuiltins did the job for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants