ajeetdsouza / zoxide

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

Error message on non-directory argument #697

Open Michel-Haber opened 5 months ago

Michel-Haber commented 5 months ago

Hello, I was trying out zoxide when I ran into the following behavior:

When I run: z <filename> where filename is an actual file not a directory, the error message I get back from zoxide is: "zoxide: no match found"

This same command with the bash cd: cd <filename> returns: "bash: cd: ./reading: Not a directory"

It would be much nicer IMO if zoxide could return a similar error message, instead of the current one, as "no match found" could imply that the target doesn't exist, rather than it not being a directory.

Fil commented 5 months ago

my number 1 ask for a better cd would be to get to the directory that contains a file, rather than error

Michel-Haber commented 5 months ago

@Fil I'm not exactly sure how I feel about that. On the one hand it may make things smoother, but on the other, it can really cause problems and confusion. Imagine the following scenario:

dir1/ | dir2/ || myfile | diir2 | myfile

Imagine wanting to erase dir1/dir2/myfile: cd dir1/dir2

But type instead: cd dir1/diir2

And then: rm myfile

In such a scenario, you might end up erasing the wrong file. I can conceive of other cases where this behavior would be problematic such as if a directory is replaced by a file and a non-updated script wreaks havoc in its parent dir.

For me an explicit error, though inconvenient in many cases, is definitely safer.