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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

support autocd option #695

wants to merge 3 commits into from

Conversation

solodov
Copy link

@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

@german-moreno283
Copy link

Would this work for zsh as well?

@solodov
Copy link
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)"
% /

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.

None yet

3 participants