ajeetdsouza / zoxide

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

error after installation if PROMPT_COMMAND is altered #722

Closed kringalf closed 4 months ago

kringalf commented 4 months ago

On my machine I use the following PROMPT_COMMAND which always updates my history file for working with multiple open shell's PROMPT_COMMAND='history -a ; ${PROMPT_COMMAND}' This causes the following error on running any command: user@host:~/scripts/git/repo/setup-my-machine (master *%=)>echo $PROMPT_COMMAND _zoxide_hook;history -a ; ${PROMPT_COMMAND} _zoxide_hook;history: command not found If i change the PROMPT_COMMAND to: PROMPT_COMMAND='history -a ;_zoxide_hook ; ${PROMPT_COMMAND}' bash crashes if i try to change a directory: `user@host:~/scripts/git/repo/setup-my-machine (master *%=)>z

Warning: Program '/bin/bash' crashed.`

ajeetdsouza commented 4 months ago

Try this:

PROMPT_COMMAND="history -a;${PROMPT_COMMAND#;}"
kringalf commented 4 months ago

Thanks for the quick response, this helped and fixed the initial issue but i still notice something strange. When i init it like this everything works like a charm:

PROMPT_COMMAND='history -a ; ${PROMPT_COMMAND#;}'
alias cd='z'
alias cdi='zi'

But if i use this method "cd" (and cdi) takes ages and seemingly randomly crashes:

eval "$(zoxide init --cmd cd bash)"
PROMPT_COMMAND='history -a ; ${PROMPT_COMMAND#;}'

Also if I use the first method twice, if i try to use cd it takes ages, and then crashes:

user@host:~>z tmp
user@host:~/tmp>eval "$(zoxide init bash)"; PROMPT_COMMAND='history -a ;${PROMPT_COMMAND#;}'
sagu@linkmobility:~/tmp>z

Warning: Program '/bin/bash' crashed.

If i do it in a subshell it looks like this:

user@host:~>date;( eval "$(zoxide init bash)"; PROMPT_COMMAND='history -a ;${PROMPT_COMMAND#;}'; z tmp );date
Tue Feb 20 23:45:30 CET 2024
Segmentation fault (core dumped)
Tue Feb 20 23:45:39 CET 2024
ajeetdsouza commented 4 months ago

What version of zoxide are you running? Are you still seeing this issue on the latest release?

kringalf commented 4 months ago

I used the version that shipped with ubuntu 22.04 ii zoxide 0.4.3-2 amd64 Faster way to navigate your filesystem once i switched to the cargo version this issue also seems to be gone, thx again :)

kringalf commented 4 months ago

issue fixed