ajeetdsouza / zoxide

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

Stack overflow in fish when `alias --save cd=z` #674

Closed kredati closed 4 months ago

kredati commented 5 months ago

Updated to MacOS 14.3 last night. Currently running Zoxide 0.9.2, installed with Homebrew (4.2.5), in Fish (3.7.0), in Kitty (0.32.1). (I also upgraded Kitty today.)

Anytime I use z (with any, or no, arguments), I get:

> z meta                                             Fri 26 Jan 11:23:10 2024
- (line 1): The call stack limit has been exceeded. Do you have an accidental infinite loop?
function z --wraps __zoxide_z --description 'alias z=__zoxide_z';  __zoxide_z $argv
                                                                   ^
in function 'z' with arguments '~/git/meta'
in function '__zoxide_cd_internal' with arguments '~/git/meta'
    called on line 23 of file -
in function '__zoxide_cd' with arguments '~/git/meta'
    called on line 55 of file -
in function '__zoxide_z' with arguments '~/git/meta'
    called on line 1 of file -
in function 'z' with arguments '~/git/meta'
in function '__zoxide_cd_internal' with arguments '~/git/meta'
    called on line 23 of file -
in function '__zoxide_cd' with arguments '~/git/meta'
    called on line 55 of file -
in function '__zoxide_z' with arguments '~/git/meta'
    called on line 1 of file -
in function 'z' with arguments '~/git/meta'
in function '__zoxide_cd_internal' with arguments '~/git/meta'
    called on line 23 of file -
in function '__zoxide_cd' with arguments '~/git/meta'
    called on line 55 of file -
...

Note that indeed meta is correctly resolved to ~/git/meta. (~ redacted for privacy reasons; z correctly lists the absolute path.)

I moved ~/Library/Application Support/zoxide/db.zo to db.zo.old, and it's still giving me the stack overflow. I also uninstalled and reinstalled Zoxide with brew.

Any help would be appreciated!

ajeetdsouza commented 5 months ago

Could you share your shell configuration?

asjur commented 5 months ago

Could you share your shell configuration?

Not OP but I am having the same issue. I installed zoxide last night and it was working great, I even aliased it to cd. Came to work today and booted up my laptop, now any z command returns this stack limit exceeded error.

I'm also using Fish, but on Linux.

What exactly config is it you need? config.fish?

Update: I removed the cd=z alias and now it doesn't happen. Does z use cd underneath perhaps?

kredati commented 5 months ago

Here is my config.fish:

if status is-interactive
    # Commands to run in interactive sessions can go here
end

function rga-fzf
    set RG_PREFIX 'rga --files-with-matches'
    if test (count $argv) -gt 1
        set RG_PREFIX "$RG_PREFIX $argv[1..-2]"
    end
    set -l file $file
    set file (
        FZF_DEFAULT_COMMAND="$RG_PREFIX '$argv[-1]'" \
        fzf --sort \
            --preview='test ! -z {} && \
                rga --pretty --context 5 {q} {}' \
            --phony -q "$argv[-1]" \
            --bind "change:reload:$RG_PREFIX {q}" \
            --preview-window='50%:wrap'
    ) && \
    echo "opening $file" && \
    open "$file"
end

zoxide init fish | source

thefuck --alias | source 

# set fzf file completion to option-tab
fzf_configure_bindings --directory=\e\t

# starship init fish | source

As @asjur notes: actually, the issue seems to lie entirely in the cd=z alias. I was able to cause the issue by alias --save cd=z, and fix the issue by deleting ~/.config/fish/functions/cd.fish.

I should say, one wrinkle is that the shell in which you alias --save cd=z works just fine, with cd aliasing z no problem. But in a new shell where the fish function runs at startup, that's when the stack overflow shows up.

So if you add alias cd=z in config.fish, you're good to go (although it breaks fish's syntax highlighting), whereas if you have a function file, cd.fish, with the following, you get the stack overflow:

function cd --wraps=z --description 'alias cd=z'
  z $argv

end
ajeetdsouza commented 5 months ago

Have you tried initializing zoxide as cd instead of z?

zoxide init fish --cmd cd | source

Also, do verify that your zoxide version is up-to-date (may be a duplicate of https://github.com/ajeetdsouza/zoxide/issues/694):

$ zoxide -V
zoxide 0.9.3
researcher2312 commented 5 months ago

I had the exact same problem, and can confirm that update fixes the error. Ubuntu repo has 0.4.3 version of zoxide and updating manually helps.

ajeetdsouza commented 4 months ago

@kredati do update to the latest version of zoxide. Ubuntu / Debian derivatives have a very outdated version. You may want to use the install script:

curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
asjur commented 4 months ago

Have you tried initializing zoxide as cd instead of z?

zoxide init fish --cmd cd | source

Also, do verify that your zoxide version is up-to-date (may be a duplicate of #694):

$ zoxide -V
zoxide 0.9.3

Aliasing using this command is what fixed it for me.

kredati commented 4 months ago

@kredati do update to the latest version of zoxide. Ubuntu / Debian derivatives have a very outdated version. You may want to use the install script:

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

I am using MacOS (14.3.1), and installed zoxide using brew. Current version is 0.9.4 (updated from 0.9.3 just now). Stack overflow persists when using fish's alias.

I do think that using alias instead of changing the init line in fish.config is an extremely normal thing to expect to be able to do with "new unix" tools like z. (E.g., I map eza to ls with alias --save ls=eza.)

If this isn't a bug to y'all, I get it. From a user's perspective, this feels like unexpected behaviour. Perhaps a note in the documentation under the "config" section would be appropriate.

Thanks for this! I love zoxide, and am grateful for everybody's work on it.

ajeetdsouza commented 4 months ago

@kredati that's a reasonable ask. However: