Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support autocd option #695

Merged
merged 3 commits into from
Jun 25, 2024
Merged

support autocd option #695

merged 3 commits into from
Jun 25, 2024

Conversation

solodov
Copy link
Contributor

@solodov solodov commented Feb 14, 2024

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

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.
just skip the first argument and pass the rest as is. checking for directory
breaks cd'ing to symlinked directories
@solodov solodov marked this pull request as draft February 15, 2024 00:11
tests are failing
@solodov solodov marked this pull request as ready for review February 15, 2024 00:52
@PhoenixmitX
Copy link

would love to see this merge

@leo283
Copy link

leo283 commented Feb 27, 2024

Would this work for zsh as well?

@solodov
Copy link
Contributor Author

solodov commented Feb 27, 2024

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
Copy link

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

@solodov
Copy link
Contributor Author

solodov commented May 31, 2024

@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
Copy link

fwam commented Jun 2, 2024

bump

@tonyOehme
Copy link

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

@ajeetdsouza ajeetdsouza merged commit 8da8f50 into ajeetdsouza:main Jun 25, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants