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 doesn't go to the previous directory #820

Closed
stephane-archer opened this issue May 20, 2024 · 9 comments
Closed

zoxide doesn't go to the previous directory #820

stephane-archer opened this issue May 20, 2024 · 9 comments

Comments

@stephane-archer
Copy link

zoxide doesn't go to the previous directory:

z -
cd: The directory '-' does not exist
zoxide 0.9.4

config.fish

if status --is-interactive
        set -x GOPATH (go env GOPATH)
        set -x PATH $PATH (go env GOPATH)/bin
        set fish_cursor_insert line
        starship init fish | source
        function __zoxide_cd_internal
                builtin cd $argv
        end
        zoxide init fish | source
end
@ajeetdsouza
Copy link
Owner

Why have you replaced the __zoxide_cd_internal function?

@ajeetdsouza ajeetdsouza added the waiting-for-response Waiting for a response from the issue author. label May 21, 2024
@stephane-archer
Copy link
Author

stephane-archer commented May 21, 2024

@ajeetdsouza because cd has been disabled with an alias to force me to use zoxide, so I need zoxide to use the built-in cd, not the alias.

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

builtin cd does not support cd -. To solve this issue, remove the custom __zoxide_cd_internal function, and disable cd after you initialize zoxide.

@stephane-archer
Copy link
Author

@ajeetdsouza
removing the custom __zoxide_cd_internal
then

if status --is-interactive
        zoxide init fish | source
end

function cd
    if status is-interactive
        echo "Use z"
        return 1
    end
    builtin cd $argv
end

doesn't work for me. I see Use z when using zoxide

@ajeetdsouza
Copy link
Owner

Your version of zoxide is likely out of date. Can you try with the latest version?

@stephane-archer
Copy link
Author

I use this version

zoxide 0.9.4

I think it's the last one?

@ajeetdsouza
Copy link
Owner

Works for me:

image

Can you check if you've set a cd alias using --save that's getting loaded before zoxide?

@stephane-archer
Copy link
Author

@ajeetdsouza This works for me now, I still had a cd defined in fish/.config/fish/function/
it's strange to me that you depend on the current cd on the system. Why did you make that choice?
Thank you for the help.

@ajeetdsouza
Copy link
Owner

Unlike most shells, Fish's builtin cd does not work with cd -, cd + etc. Instead, it's defined in a separate function that internally calls builtin cd. I believe on one of their GitHub issues they mentioned moving all this logic into the builtin, but that has not been picked up yet.

In other shells, zoxide depends on builtin cd (or equivalent) which is useful when users alias cd to something else, but on Fish, the only options seem to be:

  1. Use builtin cd and don't support cd - / cd + / etc.
  2. Copy the original cd function verbatim from Fish's repo into zoxide, and use that.
  3. Upon startup, copy the cd function that is available into __zoxide_cd_internal. The condition here is that you must only alias cd after initializing zoxide.

Option 2 will use FIsh's internal variables for tracking the directory stack, but if any of them get renamed in a later Fish version, or if the function uses some newer features of Fish, it will behave differently. For that reason, I picked option 3, but it's causing enough confusion that I'm considering moving to option 2.

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

No branches or pull requests

2 participants