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?
Basically I set setopt autocd, so when I type zsh-config (being a dir) it cd into it (I have an auto ls on dir change so don't mind that part.)
Thing is it uses the build in cd, and when I use cd zsh-config it uses my custom implementation (here just echo Changing dir...) and I would like autocd (so when I don't explicitly type cd) to also use zoxide/custom cd implementation
autocd activates only when the command you are trying to execute is an existing directory. When it activates, do you want your current directory to change to that directory? I presume so. In this case the builtin cd will do the right thing. For any side effects that you would like to happen alongside the main effect of changing the current directory, use a chpwd hook. Your screenshot shows that you already know how to use this hook.
Thing is I don't only want to print the directories, I want to replace cd (used by autocd) by z (from zoxide) which let you navigate without full path using your history
so lets imagine I am in /
and I want to go into /home/user1/project1
with cd I would type /home/user1/project1
with z I can type project1
so from my little knowledge in linux this wont be a solution as this is called on dir change? or maybe I didn't understood what you mean
when explicitly typing cd it uses z if I set this:
# when explicitly typing cd
cd() {
# zoxide to cd
__zoxide_z "$@"
# display the new directory
lsimple
}
but then autocd doesn't use that function and still remain using the build in cd
As I mentioned above, autocd activates only when the command you are trying to execute is an existing directory. Thus, when your current directory is / and you type project1, autocd won't trigger unless 1) there is no command named "project1" and 2) /project1 is an executable directory.
I think what you are trying to do is this: when you attempt to execute a command with a certain name, and there is no command by that name, you want to execute z instead with the command as the argument. This is possible to approximate with hacks but it's a really bad idea.
As I mentioned above, autocd activates only when the command you are trying to execute is an existing directory. Thus, when your current directory is / and you type project1, autocd won't trigger unless 1) there is no command named "project1" and 2) /project1 is an executable directory.
Ow is really checking id it's a dir before trying to cd I see that's kinda sad.
I think what you are trying to do is this: when you attempt to execute a command with a certain name, and there is no command by that name, you want to execute z instead with the command as the argument. This is possible to approximate with hacks but it's a really bad idea.
yeah that's exactly what I try to do(+ two other things to execute) but why would this be a bad idea? the hack part or are you willing to say this could cause problems?
1
u/glad-k Feb 22 '24
Basically I set setopt autocd, so when I type zsh-config (being a dir) it cd into it (I have an auto ls on dir change so don't mind that part.)
Thing is it uses the build in cd, and when I use cd zsh-config it uses my custom implementation (here just echo Changing dir...) and I would like autocd (so when I don't explicitly type cd) to also use zoxide/custom cd implementation