zoxide icon indicating copy to clipboard operation
zoxide copied to clipboard

__zoxide_hook:2: command not found: zoxide

Open MarsLyukova opened this issue 1 year ago • 3 comments

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?

MarsLyukova avatar Feb 16 '24 09:02 MarsLyukova

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

ajeetdsouza avatar Feb 20 '24 21:02 ajeetdsouza

I am calling it manually in the shell.

MarsLyukova avatar Feb 21 '24 08:02 MarsLyukova

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.

ajeetdsouza avatar Feb 25 '24 21:02 ajeetdsouza

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.

MarsLyukova avatar Mar 01 '24 11:03 MarsLyukova

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/

ajeetdsouza avatar Mar 13 '24 03:03 ajeetdsouza