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 init --cmd cd bash' causing using cd to crash terminal #694

Closed
xyzme2 opened this issue Feb 14, 2024 · 18 comments
Closed

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

xyzme2 opened this issue Feb 14, 2024 · 18 comments
Labels
waiting-for-response Waiting for a response from the issue author.

Comments

@xyzme2
Copy link

xyzme2 commented Feb 14, 2024

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?

@MaximSrour
Copy link

MaximSrour commented Feb 15, 2024

I also have this issue in some cases.

On Windows 10 through WSL (Ubuntu 22.04.2) the commands work just fine. On a native Linux machine (Ubuntu Server 22.04.3) it has similar behaviour. Rebinding z and zi to cd and cdi will cause the crash, as well as leaving the z and zi commands as is.

I am using SSH from my WSL shell into the native box.

@M0hammedImran
Copy link

I am facing the same issue in zsh.
This is in my .zshrc
image

When I run cd I get this error
image.

image

@didi-maru
Copy link

I have a similar issue with fish

@TheBloodyScreen
Copy link

I have the same issue using both bash and zsh.

@iskaron
Copy link

iskaron commented Feb 15, 2024

I am facing the same issue in zsh. This is in my .zshrc image

When I run cd I get this error image.

image

And _z_cd links back to cd:

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

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

so it is definitively a recursion. Same on bash as well on zsh.

@NoNamePaul94
Copy link

NoNamePaul94 commented Feb 15, 2024

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")

@favna
Copy link

favna commented Feb 15, 2024

Chiming in that I'm facing the same issue with zsh, but only on my Linux servers, one is running Ubuntu (server) 22.04.3 LTS x86_64 and the other Debian GNU/Linux 11 (bullseye) x86_64. On my host (macOS 14.2.1 23C71 x86_64) it works just fine. All of them use similar setups of zsh + oh-my-zsh as shell and Starship as prompt for as much as that is worth. I have applied the workaround from NoNamePaul, but even delegating it to a separate file (.zoxide.sh) to source, it's still quite a bit of stuff for what should be an easy setup.

@Deedone
Copy link

Deedone commented Feb 15, 2024

Having the same issue with zsh, installed from apt and running eval $(zoxide init zsh --cmd cd)

@J4yTr1n1ty
Copy link

+1 for me as well on Ubuntu 22.04 WSL running with eval "$(zoxide init --cmd cd bash)"

@0PandaDEV
Copy link

same issue for me here cd also returns
cd:1: maximum nested function level reached; increase FUNCNEST?

@ajeetdsouza
Copy link
Owner

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

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

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 reinstalled using cargo.
image

It works.

@wlarch
Copy link

wlarch commented Feb 15, 2024

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

@iskaron
Copy link

iskaron commented Feb 15, 2024

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

ah sorry for the inconvenience, I would have never thought of that. Yes, that fixed it for me, thanks!

@ajeetdsouza
Copy link
Owner

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

@kbcmdba
Copy link

kbcmdba commented Feb 22, 2024

Just had the same issue on my Ubuntu 22.04.3 system where I installed zoxide using

sudo apt install zoxide fzf

@ajeetdsouza
Copy link
Owner

@kbcmdba the solution is posted in the thread.

@kbcmdba
Copy link

kbcmdba commented Feb 23, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-response Waiting for a response from the issue author.
Projects
None yet
Development

No branches or pull requests