ajeetdsouza / zoxide

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

zoxide doesn't go to the previous directory #820

Closed stephane-archer closed 1 month ago

stephane-archer commented 1 month ago

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 commented 1 month ago

Why have you replaced the __zoxide_cd_internal function?

stephane-archer commented 1 month ago

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

ajeetdsouza commented 1 month ago

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 commented 1 month ago

@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 commented 1 month ago

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

stephane-archer commented 1 month ago

I use this version

zoxide 0.9.4

I think it's the last one?

ajeetdsouza commented 1 month ago

Works for me:

image

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

stephane-archer commented 1 month ago

@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 commented 1 month ago

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.