ajeetdsouza / zoxide

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

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

Closed xyzme2 closed 5 months ago

xyzme2 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

I have a similar issue with fish

TheBloodyScreen commented 5 months ago

I have the same issue using both bash and zsh.

iskaron commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

J4yTr1n1ty commented 5 months ago

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

0PandaDEV commented 5 months ago

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

ajeetdsouza commented 5 months ago

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
M0hammedImran commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

kbcmdba commented 4 months ago

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

sudo apt install zoxide fzf

ajeetdsouza commented 4 months ago

@kbcmdba the solution is posted in the thread.

kbcmdba commented 4 months ago

Thanks for that. I got it. Everything seems to be working fine.

Get Outlook for iOShttps://aka.ms/o0ukef


From: ajeetdsouza @.> Sent: Thursday, February 22, 2024 4:38:45 PM To: ajeetdsouza/zoxide @.> Cc: KB Benton @.>; Mention @.> Subject: Re: [ajeetdsouza/zoxide] 'zoxide init --cmd cd bash' causing using cd to crash terminal (Issue #694)

@kbcmdbahttps://github.com/kbcmdba the solution is posted in the thread.

— Reply to this email directly, view it on GitHubhttps://github.com/ajeetdsouza/zoxide/issues/694#issuecomment-1960361296, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZ2PFL6DWNM4SMZUO4GGYDYU63GLAVCNFSM6AAAAABDJI67L6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRQGM3DCMRZGY. You are receiving this because you were mentioned.Message ID: @.***>