zoxide: 'zoxide init --cmd cd bash' causing using cd to crash terminal

Hello,

just installed zoxide and I seem to be having difficulties with the --cmd flag. If i set the line in my bashrc to eval "$(zoxide init --cmd cd bash)" then when I use cd it will hang for a minuite or so then either do nothing or crash the terminal.

Interestingly it only seems to happen when it is set to cd. Though setting it to ‘ls’ gives the following error message when I boot my terminal

bash: eval: line 130: syntax error near unexpected token `('
bash: eval: line 130: `ls() {'

setting it to other options seems to work fine (i.e. j, test) it seems for now a simple alias will work, but I’m certain the --cmd flag exist for a reason.

Am I missing something on how to set up or is this non-expected behavior?

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 2
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Debian / Ubuntu derivatives package a very old version of zoxide in their repositories. The latest version shouldn’t have this problem - could you try using the install script?

curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash

I had the same issue as mentioned by others when installing using Debian apt package manager : cd:1: maximum nested function level reached; increase FUNCNEST?

Installing zoxide using the installation script did the trick : curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash

I also have this issue with ZSH maximum nested function level reached; increase FUNCNEST?

Edit: I fixed this by replacing the eval "$(zoxide init --cmd cd zsh)" call in my .zshrc profile with a modified version of its output. The only thing I added is a builtin in front of the cd command in the _z_cd function.

This is the output from zoxide init --cmd cd zsh with my modification:

_z_cd() {
    builtin cd "$@" || return "$?"

    if [ "$_ZO_ECHO" = "1" ]; then
        echo "$PWD"
    fi
}

cd() {
    if [ "$#" -eq 0 ]; then
        _z_cd ~
    elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then
        if [ -n "$OLDPWD" ]; then
            _z_cd "$OLDPWD"
        else
            echo 'zoxide: $OLDPWD is not set'
            return 1
        fi
    else
        _zoxide_result="$(zoxide query -- "$@")" && _z_cd "$_zoxide_result"
    fi
}

cdi() {
    _zoxide_result="$(zoxide query -i -- "$@")" && _z_cd "$_zoxide_result"
}


alias cda='zoxide add'

alias cdq='zoxide query'
alias cdqi='zoxide query -i'

alias cdr='zoxide remove'
cdri() {
    _zoxide_result="$(zoxide query -i -- "$@")" && zoxide remove "$_zoxide_result"
}


_zoxide_hook() {
    zoxide add "$(pwd -L)"
}

chpwd_functions=(${chpwd_functions[@]} "_zoxide_hook")

I’ve edited the README to strike out outdated package repositories to prevent future confusion. Thanks!