ajeetdsouza / zoxide

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

__zoxide_hook:2: command not found: zoxide #704

Closed MarsLyukova closed 4 months ago

MarsLyukova commented 5 months ago

Hello, I have a problem using zoxide while setting up an enviroment via a script.

Setup

This is my ~/.zshrc

# zxoide ZSH
export PATH="$HOME/.local/bin:$PATH"
eval "$(zoxide init zsh)"

This is my ~/.bashrc

# zxoide bash
export PATH="$HOME/.local/bin:$PATH"
eval "$(zoxide init bash)"

With this, I am able to use the z command as expected in both bash and zsh shells. I have not setup --cmd.

The issue:

I have a development enviroment setup by a script. In zsh I obtain the below output

source ./<internal_setup_script>.sh
# A bunch of expected output ...
__zoxide_hook:2: command not found: zoxide

Using bash, the __zoxide_hook:2: command not found: zoxide line is not present. From debugging, I found the problematic line to be x=$(\cd "$x";\pwd)

# If x is an existing directory, get its absolute path:
if [ -d "$x" ] && [ -r "$x" ] && [ -x "$x" ]; then
    # This line below causes '__zoxide_hook:2: command not found: zoxide'
    x=$(\cd "$x";\pwd)
fi

Removing eval "$(zoxide init zsh)" also removes the errors, but of course I can't use z. Is there any idea why I am obtaining this __zoxide_hook:2 error?

ajeetdsouza commented 4 months ago

Where are you calling source ./<internal_setup_script>.sh? Is it in your zshrc file, or are you calling it manually in your shell?

MarsLyukova commented 4 months ago

I am calling it manually in the shell.

ajeetdsouza commented 4 months ago

Seems like your shell script is resetting your PATH for some reason. Try adding an echo $PATH before the problematic line to see if ~/.local/bin has been removed.

MarsLyukova commented 4 months ago

Hi @ajeetdsouza , I added echo $PATH and it is indeed the case that ~/.local/bin is removed from PATH. I cannot change these scripts, so I am OK with closing the issue if one of the requirements of using zoxide is that PATH must always keep ~/.local/bin.

Edit: Also as a correction, I did use --cmd cd when testing. I removed it after obtaining these errors.

ajeetdsouza commented 4 months ago

You could try moving the zoxide binary to a directory that is contained in $PATH. For example, if you have /usr/local/bin available in your PATH:

sudo mv ~/.local/bin/zoxide /usr/local/bin/