mgunyho / tere

Terminal file explorer
European Union Public License 1.2
1.68k stars 38 forks source link

Add an option to show both files and folders but search only folders #87

Closed kovdan01 closed 1 year ago

kovdan01 commented 1 year ago

Since tere is used to browse the filesystem fast and not to open files, searching for files is not very useful (we can't chdir into a file :) ). There is already an option --folders-only, but it disables not only search through files but there display as well. Having files displayed makes sense as for me: for example, you don't need to run ls after exiting from tere to see what's inside the folder.

Having a special mode where files are displayed but not searched would give the best of two existing options: both seeing everything immediately and rapid browsing the filesystem without files being treated as potential chdir targets.

mgunyho commented 1 year ago

Hi, thanks for the suggestion!

This sounds like a decent addition, and it should not conflict too badly with an xdg-open-like use-case such as in #38, if that's ever implemented.

What could be an easy-to-understand --option-name for this? The existing -d/--folders-only and -D/--no-folders-only are a bit hard to extend to this. One possibility is to deprecate -d and -D and use a three-way option instead, like --files <'select', 'ignore' or 'hide'>, as the sorting mode is now.

I might implement this but I don't have much time in the near future. A PR is welcome.

mgunyho commented 1 year ago

Hmm on further thought, maybe the default behavior should be to just not select files when searching, since tere can't do anything with them for now anyway. An --option for allowing file selection could be added later.

mgunyho commented 1 year ago

Okay this turned out to be trivial to implement: https://github.com/mgunyho/tere/commit/35fee62129a3deeca8e9a908584a0f784c0b0924.

I'll probably make this the default behavior, but I would like to add an option for enabling searching for files as well.

One use case I can think of is that one wants to check if a folder contains some files, e.g. with the filter-search mode. So similarly to your case of not wanting to do ls after entering a folder, one might want to search for some file within a folder, and decide based on that if this was the folder they wanted or not.

kovdan01 commented 1 year ago

Thanks @mgunyho!

What could be an easy-to-understand --option-name for this? The existing -d/--folders-only and -D/--no-folders-only are a bit hard to extend to this. One possibility is to deprecate -d and -D and use a three-way option instead, like --files <'select', 'ignore' or 'hide'>, as the sorting mode is now.

A three-way option looks best as for me. A separate --option-name might be a bit confusing since combination of "folders-only" and "search-both-files-and-dirs" makes no sense, and only 3 combinations out of 4 in this 2x2 matrix are intended to be used.

However, if a three-way option is harder to implement for some reason, a separate option also looks quite well. The names might be like --search-folders-only and --no-search-folders-only. I'm not very good in nice names, but these at least look consistent with existing --folders-only and --no-folders-only.

mgunyho commented 1 year ago

A separate --option-name might be a bit confusing since combination of "folders-only" and "search-both-files-and-dirs" makes no sense, and only 3 combinations out of 4 in this 2x2 matrix are intended to be used.

I was thinking of it as a third option that would override both --folders-only and --no-folders-only, like how the case-sensitivity has three options, --case-sensitive, --ignore-case and --smart-case, so we only have 3 options and not 2x2. It's just hard to come up with a name to complement "folders only" and "no folders only". It feels to me that it should be something like "hide files", "ignore files" and "allow both files and folders".

kovdan01 commented 1 year ago

Ah, I got your point now. I agree that it's hard to come up with a nice complement to 2 existing option names, and I was unable to do that in a reasonable time as well. I'll let you know if something comes to my mind, but I suppose it's unlikely to happen.

mgunyho commented 1 year ago

Thanks for taking the time to think about it! I also tried to think of a reasonable option, but I also came to the conclusion that the three-way option is better. I'm currently working on implementing it with --files ignore|hide|match.

mgunyho commented 1 year ago

It took a while, but this is now implemented by #88. I will make a new release with this feature soon.

I went with --files ignore|hide|match, with the short version -l (I initially wanted to use -d, but it was tricky to re-use an existing shorthand without causing compatibility issues).

kovdan01 commented 1 year ago

Thanks!