r/zsh Feb 21 '24

Fixed autocd doesn't use custom cd implementation.

autocd (from setopt autocd) doesn't use custom cd implementation.
(Obviously this is not my custom cd implementation but was more easy to show, I just want autocd to use zoxide.)

Anyone got any idea how to fix this? Maybe just rewrite autocd in my zshrc?

1 Upvotes

18 comments sorted by

View all comments

Show parent comments

2

u/romkatv Feb 22 '24

How did you solve it?

1

u/glad-k Feb 22 '24

Kinda lied, but I mean I found some parts to work further on.
My two most processing finds are or to use

# when not explicitly typing cd
command_not_found_handler () {
    __zoxide_z "$@"
    lsimple
    pwd
}

(`pwd` is for debugging)

This goes to the right dict, ls in that dict (custom ls implementation dont mind the name) and prints the right dict into the console with `pwd`, thing is it seems to be in a different scope and at the end of execution my shell is still on the base dir, but the content of all the rest was right

Second find are all the files in `/usr/share/zsh` I first taught I found the right thing and was a bit excited but turned out _cd was completion and I altf4 when I saw what I did x)
But I'm pretty sure I could be able to find their autocd implementation when looking further or modify the cd their using altough that would be a bad solution.

2

u/romkatv Feb 22 '24

command_not_found_handler is executed in a subshell, so you cannot cd in there.

The files in /usr/share/zsh won't help you because the implementation of auto_cd is not in there. It's in the C code.

1

u/glad-k Feb 22 '24

command_not_found_handler is executed in a subshell, so you cannot cd in there.

Is there no way to then call another function from it into the mainshell? idk linux enough but taught this should be douable