ajeetdsouza / zoxide

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

support autocd option #695

Closed solodov closed 3 weeks ago

solodov commented 5 months ago

In bash, when autocd option is set and user enters a directory name as a command, it results in a very specific call to cd:

cd -- [directory name]

zoxide's directory changing function passes all arguments to __zoxide_z as is, including the "--" first argument. By detecting this and skipping the first argument changing directory works with autocd set.

This particular bug only happens when initializing zoxide with --cmd cd. Here's how it breaks in bash:

$ shopt -c autocd
$ eval $(zoxide init --cmd cd bash)"
$ ..
cd -- ..
zoxide: no match found
PhoenixmitX commented 4 months ago

would love to see this merge

leo283 commented 4 months ago

Would this work for zsh as well?

solodov commented 4 months ago

Would this work for zsh as well?

I updated the initial comment with reproduction steps for bash. Checked in zsh and seems to work correctly already:

% setopt  autocd
% eval "$(zoxide init --cmd cd zsh)"
% /
charlesbvll commented 1 month ago

@ajeetdsouza Is there any update on this? Seems like a very useful feature to have!

solodov commented 1 month ago

@ajeetdsouza Is there any update on this? Seems like a very useful feature to have!

PR is ready to be merged, as far as I'm concerned. I've been using this fix for a few months now, everything seems to be ok.

fwam commented 1 month ago

bump

tonyOehme commented 3 weeks ago

This seems like a neat improvement. @ajeetdsouza any updates on this?