ajeetdsouza / zoxide

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

Zoxide not adding to db.zo unless you run init again #723

Closed aidandeli closed 7 months ago

aidandeli commented 7 months ago

WSL2, kali linux version 2023.3, zoxide version 0.9.3

I installed via the install script. Whenever I navigate anywhere after first opening a terminal window, I noticed the zoxide database doesn't create entries unless I run eval "$(zoxide init --cmd cd bash)" again. My .bashrc does have that line, yes.

I can confirm that zoxide is working, as you can see at the second and third prompts in the image.

If we were to move to a brand new directory, we'd assume zoxide would add the new path to db.zo. However, if you look at the image below, you can see that zoxide doesn't update db.zo.

Observe that, after I run eval "$(zoxide init --cmd cd bash)" again, that zoxide starts tracking the directories I go to, and the db file grows.

image

kringalf commented 7 months ago

I have the same issue on ubuntu 22.04 but running eval "$(zoxide init bash)" again doesn't solve the issue here, the db file only grows if i call zoxide add . in the directory

user@host:~>zoxide --version; fzf --version; alias cd;mkdir /tmp/new_dir;stat --printf="%s\n" ~/.local/share/zoxide/db.zo; cd /tmp/new_dir; cd; stat --printf="%s\n" ~/.local/share/zoxide/db.zo
zoxide 0.9.4
0.46.1 (3c0a630)
alias cd='z'
165
165
ajeetdsouza commented 7 months ago

It's possible something else is overriding the prompt. Could you try making zoxide init the last line in your shell config?

kringalf commented 7 months ago

Note: This is only usefull for my setup since i wanna use the history command in a non default way. So this might only be helpfull for users that also change the bash environment variable PROMPT_COMMAND on their system For me, with my history -a addon, it helped setting the PROMPT_COMMAND to:

PROMPT_COMMAND="history -a ; __zoxide_hook;${PROMPT_COMMAND#;}"

Now the db file increases after using cd to a new dir

aidandeli commented 7 months ago

eval "$(zoxide init --cmd cd bash)" is the last line in my config file.

I added the line @kringalf mentioned but I'm still having no luck.

ajeetdsouza commented 7 months ago

@aidandeli what's the output of echo "$PROMPT_COMMAND"? It should contain __zoxide_hook, otherwise something is overriding your prompt.

aidandeli commented 7 months ago

Ah yeah, the output was just echo

Adding export PROMPT_COMMAND="__zoxide_hook;echo" after zoxide init in my config file fixed it.

ajeetdsouza commented 7 months ago

Ah yeah, the output was just echo

That typically means something is running after zoxide init and overriding your PROMPT_COMMAND. You can use set -x in your .bashrc to debug this.

slak44 commented 7 months ago

It might be a good idea to mention PROMPT_COMMAND in the documentation somewhere, as the reason why zoxide should be last. I set that variable in my bash config as well, and until @kringalf mentioned it in his comment, I didn't notice the order.