grml-etc-core icon indicating copy to clipboard operation
grml-etc-core copied to clipboard

zshrc: smarter smarter cd

Open moviuro opened this issue 2 years ago • 2 comments

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

moviuro avatar Jul 25 '22 21:07 moviuro

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

mika avatar Jul 25 '22 21:07 mika

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!

moviuro avatar Jul 25 '22 21:07 moviuro