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

zshrc: smarter smarter cd #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

zshrc: smarter smarter cd #142

wants to merge 1 commit into from

Conversation

moviuro
Copy link
Contributor

@moviuro moviuro commented Jul 25, 2022

We have to account for a lot of possibilities (see zshbuiltins(1)): we stay on the safe side and only change cd target if we're sure about what we do. See examples:

% zsh -d -f             # reset the shell
% cd
% touch -- -q
% cd -q                 # should do nothing; 43090cf version behaves weirdly here, replacing -q with .
% cd /home
% cd /home /etc         # should go to /etc (replace home with etc in PWD)
/etc
% cd /home /etc         # this will fail [1]
cd: string not in pwd: /home
% cd /home
% cd -q /home /etc      # should go to /etc
/etc
% cd -q /home /etc      # this will fail [2]
cd: string not in pwd: /home
% cd
% touch +123456
% cd +123456            # this will fail [3]; 43090cf version behaves weirdly here, replacing +123456 with .

[1]   I chose to make this one work. If `cd old new` fails, then try to
      `cd old`
[2,3] I chose to fail too in that case. Handling cd arguments is not what
      I was planning to do when I started working on this patch ;P

We have to account for a lot of possibilities (see zshbuiltins(1)): we
stay on the safe side and only change cd target if we're sure about what
we do. See examples:

% zsh -d -f             # reset the shell
% cd
% touch -- -q
% cd -q                 # should do nothing; 43090cf version behaves weirdly here, replacing -q with .
% cd /home
% cd /home /etc         # should go to /etc (replace home with etc in PWD)
/etc
% cd /home /etc         # this will fail [1]
cd: string not in pwd: /home
% cd /home
% cd -q /home /etc      # should go to /etc
/etc
% cd -q /home /etc      # this will fail [2]
cd: string not in pwd: /home
% cd
% touch +123456
% cd +123456            # this will fail [3]; 43090cf version behaves weirdly here, replacing +123456 with .

[1]   I chose to make this one work. If `cd old new` fails, then try to
      `cd old`
[2,3] I chose to fail too in that case. Handling cd arguments is not what
      I was planning to do when I started working on this patch ;P
@mika
Copy link
Member

mika commented Jul 25, 2022

Thanks, @moviuro - any objections against merging this as-is from your side, @ft?

@moviuro
Copy link
Contributor Author

moviuro commented Jul 25, 2022

You probably want to run some more tests on it. I ran a few and made sure my usecases were covered, though I might have missed some.

Even got to learn about zshbuiltins(1) in the process!

ImOdd

This comment was marked as spam.

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.

3 participants