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

Fish: Allow cd aliasing #145

Closed
fennewald opened this issue Feb 2, 2021 · 18 comments · Fixed by #146 or #207
Closed

Fish: Allow cd aliasing #145

fennewald opened this issue Feb 2, 2021 · 18 comments · Fixed by #146 or #207

Comments

@fennewald
Copy link
Contributor

Really cool plugin, just started using it with fish.

Ran into issue trying to alias cd to z, where zoxide tries to call my alias, which calls zoxide, which calls my alias, until stack overflow.

zoxide init fish outputs this internal command (among other things):

function __zoxide_cd
    cd $argv
    and commandline -f repaint
end

However, it should be:

function __zoxide_cd
    command cd $argv
    and commandline -f repaint
end

In fish, command makes sure to call out instead of calling functions.

I'm not familiar with zoxide's codebase, so I didn't know where to put the fix, otherwise I'd PR myself.

@thaliaarchi
Copy link

The fix looks like it would be on this line.

@dnlmlr
Copy link
Contributor

dnlmlr commented May 9, 2021

I would like to reopen this issue since it still (or more like again) exists

Since the referenced pullrequest was merged, the line in question was first changed in 7b00d5a and then fully reverted in acc9059 .

I just started trying out fish, so I don't know a lot about it. Anyways: As far as I understand, the problem is that fish provides a builtin cd command, as well as a function wrapping the builtin command with extra functionality. So just using builtin cd in the fish template would remove that added functionality.

I also have an idea on how this could be solved:

The recursion problem occurs when using alias cd=z because zoxides z will simply call cd in the end and therefore call itself again.
One solution might be to use functions -c to copy fishs original cd function into something like __fish_cd and use that in zoxides fish template.

That might look like this:

# At the beginning of the fish template create the copy, but only if it doesn't exists yet to keep idempotency
if ! type -q __fish_cd
    functions -c cd __fish_cd
end

And then in the __zoxide_cd function use __fish_cd $argv instead of cd $argv

I'll create a pull request when I find the time, except if you give a reason why this is bad before that 😄

@ajeetdsouza ajeetdsouza reopened this May 9, 2021
@ajeetdsouza
Copy link
Owner

@dnlmlr that's a great idea, go ahead.

@federicotorrielli
Copy link

This problem is still present for me: I'm multiple-sourcing the config.fish (starship and zoxide) and placing the alias after the source, but it's still creating the recursive call @ajeetdsouza

image

@ajeetdsouza
Copy link
Owner

@federicotorrielli are you compiling and running the latest commit from GitHub? Because this feature hasn't made it into a point release yet.

@federicotorrielli
Copy link

I'm so stupid, I forgot to check the release tab!
No I just installed the AUR package and that's all, sorry again! @ajeetdsouza

@ajeetdsouza
Copy link
Owner

Haha, that's alright! I'll create a release for this sometime soon.

@pnunn
Copy link

pnunn commented Nov 10, 2022

I've just done a fresh install of zoxide from apt on a kde neon install and have the infinite loop issue with fish still.

The initial apt install was an old version by the looks of things so I have now purged that and got 0.8.3 deb and installed that, but, I get the same effect if I alias cd z in my config.fish.

Peter.

@ajeetdsouza
Copy link
Owner

@pnunn can you verify that you're actually on the latest version?

zoxide --version

@pnunn
Copy link

pnunn commented Nov 10, 2022

Thanks @ajeetdsouza. That returns 0.8.3 so it seems to be the correct version.

@ajeetdsouza
Copy link
Owner

@pnunn I can't reproduce this. Could you create a fresh issue with your setup, etc?

@Vixeliz
Copy link

Vixeliz commented Nov 10, 2022

I would like to add I'm also on latest release and the issue is still present. I'm on arch Linux without too many changes to fish. I personally am just dealing with it now and trying to build muscle memory with z instead of cd but wanted to mention it doesn't seem to be completely isolated.

@ajeetdsouza
Copy link
Owner

@Vixeliz do open a new issue with your fish version and configuration.

@MZH-Amr
Copy link

MZH-Amr commented Apr 26, 2024

@Vixeliz
Very late but try putting alias cd="z" after zoxide init fish | source

@pnunn
Copy link

pnunn commented Apr 26, 2024

Nope @MZH-Amr same thing still happens. Sorry... it's been a long time since I looked at this.
I was on a very old version... updated to 0.9.4 and boom... it works

YAY

@hoducha
Copy link

hoducha commented May 17, 2024

I got the recursion issue but it's my mistake by manually save the alias using alias --save cd="z". If you have done that like me then you can do the steps below to fix it:

  • Remove the alias function: rm ~/.config/fish/functions/cd.fish
  • Add the alias in the config file ~/.config/fish/config.fish. Note that the alias has to be placed after the zoxide init fish | source otherwise you will get the recursion issue.
...
zoxide init fish | source
alias cd="z"
...
  • Restart the shell.

@Joachim-42he
Copy link

Joachim-42he commented May 21, 2024

As per the documentation, you can achieve the same with

zoxide init --cmd cd fish | source

@callisto1232
Copy link

@Vixeliz Very late but try putting alias cd="z" after zoxide init fish | source

It worked. Thank you

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