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

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

Closed
kredati opened this issue Jan 26, 2024 · 9 comments · Fixed by #732
Closed

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

kredati opened this issue Jan 26, 2024 · 9 comments · Fixed by #732

Comments

@kredati
Copy link

kredati commented Jan 26, 2024

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 ajeetdsouza added the waiting-for-response Waiting for a response from the issue author. label Feb 12, 2024
@ajeetdsouza
Copy link
Owner

Could you share your shell configuration?

@asjur
Copy link

asjur commented Feb 15, 2024

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
Copy link
Author

kredati commented Feb 15, 2024

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

@github-actions github-actions bot removed the waiting-for-response Waiting for a response from the issue author. label Feb 15, 2024
@kredati kredati changed the title Stack overflow on any use of z Stack overflow in fish when alias --save cd=z Feb 15, 2024
@ajeetdsouza
Copy link
Owner

ajeetdsouza commented Feb 15, 2024

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

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

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
Copy link
Owner

@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
Copy link

asjur commented Feb 20, 2024

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
Copy link
Author

kredati commented Feb 21, 2024

@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.

@github-actions github-actions bot removed the waiting-for-response Waiting for a response from the issue author. label Feb 21, 2024
@github-actions github-actions bot reopened this Feb 21, 2024
@ajeetdsouza
Copy link
Owner

@kredati that's a reasonable ask. However:

  • cd is provided by the shell, and zoxide needs to use it internally to change the directory.
  • On other shells, one can use builtin cd directly (and avoid the infinite loop problem), but on Fish, the builtin is wrapped with a function that we need to use.
  • Since this can't be solved directly, I've created Detect infinite loop on Fish #732 to warn the user when such an error occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants